You save output in a file with >. To save it in a variable, use $( ): the shell runs the command inside first, then puts its output in the line.
learner@reef:~$ STAFF=$(wc -l < ~/shop/shifts.txt) ← with <, wc writes only the number
learner@reef:~$ echo "staff: $STAFF, day: $(date +%A)" ← $( ) works inside "…" too
staff: 2, day: Wednesdaydate +%A writes the name of the day.
-
At the prompt, save the number of lines in
~/orders.txtin the variableORDERS, with$( ). -
The same way, save the number of
ERRORlines in~/logs/register.loginERRORS. -
Write
~/report.sh, with#!/bin/bashon top, that prints the two counts in one line. A script doesn't see the variables you set at the prompt: give it its own two$( )lines. Make it runnable and run it:textlearner@reef:~$ ./report.sh orders: 5, errors: 3
Objectives
- At the prompt, save the number of lines in
~/orders.txtinORDERS. - Save the number of
ERRORlines in~/logs/register.loginERRORS. - Write
~/report.sh, which counts each time it runs and prints the line.