I have a list of commands in a file called cmds
, one command per line.
I want to grab the last command, set it in a variable last_command
and run it later. with $last_command
or "$last_command"
, or whatever is more appropriate.
I start by getting the last command:
$ last_command="$(cat cmds | tail -1)"
$ echo $last_command
cat file1 file2 file\ 3
The last line of cmds
was cat cat file1 file2 file\ 3
.
The problem is, when I run "$last_command"
, it will not know that the space between file
and 3
is part of the file name and give me an error.