You're assuming that your second call to awk will get something from test.txt, which it doesn't. Also piping anything to cd will not work as cd is not a real program but a shell builtin command. The
The text from cat test.txt
is is piped to cd, which doesn't do anything with it. After that, you launch awkthe command after the pipe and the command in it's ownthe sub-shell
using backticks. There is no connection between the (the first awk in) receives all the sub-shell andinput, leaving no input for the second catawk, as kojiro already answered.
You want to read a line fromWhile merging both test.txtawk, split it up, build a path and change commands will fix the directory to said path.problem, is is not guaranteed that this will work in other
This can be done as follows:
cat test.txt | read first last; cd "/folder/p/$first/$last"
I assume the following layout for testshells.txt:
firstdirectory lastdirectory
This Because many people confuse bash with 'shell' in general I think it's noteworthy that a more portable solution has problems whenwould be the first directory string contains whitespaces as read uses them as
a separator. It is just an example to start withone made by Beta.