Originally Posted by
elfstone214
Jergar,
thanks but I tried that you said and it created a directory called grep, and another called case
It sounds like you used quotes instead of backticks.
Quote: '
backtick: `
The difference is subtle, which leads to some frustrating misunderstandings when reading or copying a script. The backticks are instructions to the shell to run a command in a sub-shell. The output of the sub-shell command is returned and can be assigned to a variable. In this case, the variable name was assigned the output of : grep case file.txt
This type of backtick substitution is useful, and used fairly often in shell scripting. Be aware that grep returns nothing if there is no match, and multiple values if there are multiple matches. Because of that, consider:
Code:
name=`head -n 1 file.txt`
if [ -z $name ]; then
mkdir $name
fi
This block of code will read the first line of the file, and then check whether or not name recieved an assignment.
Bookmarks