Quote:
Originally Posted by mamba24
That was the last portion of a lengthy assignment. I have been working on that specific exercise for three days. I tried contacting people in the class and the prof with no response. This was my last resort and I appreciate your help. Could you explain what you did?
|
Well David is correct in all he said.
But to explain what was done:
Code:
filename="$(echo ${NAME} | tr ' ' '-' | tr 'A-Z' 'a-z')-quotes"
$(command) is command substitution. It assigns the value returned by the command to the variable filename.
Now the actual commands:
The '|' is a pipe. Basically, it sends the output of the first command to the input of the second command.
So the command:
Code:
"$(echo ${NAME} | tr ' ' '-' | tr 'A-Z' 'a-z')-quotes"
If NAME is Larry Wall:
$( : Start command substitution
echo ${NAME}: Get the value stored in var NAME
| : send the output of echo ${NAME} to the next command. The next command gets Larry Wall as it's input
tr ' ' '-' : translate all space to emdash (-). This produces Larry-Wall
| : Send Larry-Wall to the input of the next command
tr 'A-Z' 'a-z' : Changes all uppercase chars to lowercase. This produces larry-wall
) : end command substitution. The result in the buffer is now larry-wall
-quotes : append '-quotes' to the result os the command substitution.
filename is therefore assigned 'larry-wall-quotes'.