These days.i’m learning the shell script for fun.When i read the manual’s example like:
set $(wc -l $title_file)
num_titles=$1
set $(wc -l $tracks_file)
num_tracks=$1
And i have the brief understanding that the command,set,specify the $1 and set the value of $1 to the num_titles.
But,i have no idea why use -l as the option for the command,set.And by the way,would any guy can explain the whole story of it?thx
Firstly
setsets an environment variable.Using the syntax
set var = valueorset var [n] = wordas per its manpage , to view the manpage typeman set.In this case set is using the second syntax to make
$1 = $(wc -1 $titlefile)and then setting num_titles to $1 as a regular variablle because of the syntax used.wcis the wordcount command, and displays lines, characters and words in a file.wc -ltells wc to count by line as per the wc manpage, to view the manpage typeman wc.See the Linux Shell Scripting Tutorial A Beginner’s handbook and the Advanced Bash-Scripting Guide for further references.