I tried to run a command by reading it from a textfile, but it failed. when i enter the exact same line it is working, tough. im suprised that it did even try to execute the move command, but got an errormessage that translates to “File or directory not found”. obviously the errormessage is not telling the truth here. can someone explain that?
s39339@compute:~/spr/man/de$ head -n7 mkdoc|tail -n1
mv nutzer.1.gz ~/public_html/man/man1/
s39339@compute:~/spr/man/de$ `head -n7 mkdoc|tail -n1`
mv: Verschieben von „nutzer.1.gz“ nach „~/public_html/man/man1/“ nicht möglich: Datei oder Verzeichnis nicht gefunden
s39339@compute:~/spr/man/de$ ls
gzip mkdoc nutzer.1 nutzer.1.gz nutzer.pod rbsh
s39339@compute:~/spr/man/de$ mv nutzer.1.gz ~/public_html/man/man1/
s39339@compute:~/spr/man/de$
I am doin this for school so an answer would be nice. the way we get to our results doesn’t matter, although what i tried seems way unnessecary.
`head -n7 mkdoc|tail -n1`is replaced by the output of the command, which ismv nutzer.1.gz ~/public_html/man/man1/. This output is then interpreted as a command, amvcommand.It fails, though, because tilde expansion has already been performed.
~is not substituted with your home directory at this point; it’s just a plain tilde character. It’s as if you had tried to executeFor the same reason you cannot use
$HOME, or a second set of backticks, or any other dynamic construct. To do that you will need to useeval, or pass the string to a second shell.