set $(wc -l $title_file)

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 set sets an environment variable. Using the syntax set var = value or set var [n] = word as per its manpage , to view the manpage type man set.

In this case set is using the second syntax to make $1 = $(wc -1 $titlefile) and then setting num_titles to $1.

wc is the wordcount command, and displays lines, characters and words in a file.

wc -l tells wc to count by line as per the wc manpage, to view the manpage type man wc.

See the Linux Shell Scripting Tutorial A Beginner's handbook and the Advanced Bash-Scripting Guide for further references.


你可能感兴趣的:(linux,shell,File,command,idea,scripting)