Skip to main content
deleted 277 characters in body
Source Link
nemo
  • 58.3k
  • 15
  • 144
  • 145

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.

You're assuming that 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 text from cat test.txt is piped to cd, which doesn't do anything with it. After that, you launch awk in it's own sub-shell using backticks. There is no connection between the awk in the sub-shell and the cat.

You want to read a line from test.txt, split it up, build a path and change the directory to said path. This can be done as follows:

cat test.txt | read first last; cd "/folder/p/$first/$last"

I assume the following layout for test.txt:

firstdirectory lastdirectory

This solution has problems when the first directory string contains whitespaces as read uses them as a separator. It is just an example to start with.

You're assuming that your second call to awk will get something from test.txt, which it doesn't. The text from cat test.txt is piped to the command after the pipe and the command in the sub-shell (the first awk) receives all the input, leaving no input for the second awk, as kojiro already answered.

While merging both awk commands will fix the problem, is is not guaranteed that this will work in other shells. Because many people confuse bash with 'shell' in general I think it's noteworthy that a more portable solution would be the one made by Beta.

added 225 characters in body
Source Link
nemo
  • 58.3k
  • 15
  • 144
  • 145

You're assuming that 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 text from cat test.txt is piped to cd, which doesn't do anything with it. After that, you launch awk in it's own sub-shell using backticks. There is no connection between the awk in the sub-shell and the cat.

You want to read a line from test.txt, split it up, build a path and change the directory to said path. This can be done as follows:

cat test.txt | read first last; cd "/folder/p/$first/$last"

I assume the following layout for test.txt:

firstdirectory lastdirectory

This solution has problems when the first directory string contains whitespaces as read uses them as a separator. It is just an example to start with.

You're assuming that 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.

You want to read a line from test.txt, split it up, build a path and change the directory to said path. This can be done as follows:

cat test.txt | read first last; cd "/folder/p/$first/$last"

I assume the following layout for test.txt:

firstdirectory lastdirectory

This solution has problems when the first directory string contains whitespaces as read uses them as a separator. It is just an example to start with.

You're assuming that 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 text from cat test.txt is piped to cd, which doesn't do anything with it. After that, you launch awk in it's own sub-shell using backticks. There is no connection between the awk in the sub-shell and the cat.

You want to read a line from test.txt, split it up, build a path and change the directory to said path. This can be done as follows:

cat test.txt | read first last; cd "/folder/p/$first/$last"

I assume the following layout for test.txt:

firstdirectory lastdirectory

This solution has problems when the first directory string contains whitespaces as read uses them as a separator. It is just an example to start with.

Source Link
nemo
  • 58.3k
  • 15
  • 144
  • 145

You're assuming that 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.

You want to read a line from test.txt, split it up, build a path and change the directory to said path. This can be done as follows:

cat test.txt | read first last; cd "/folder/p/$first/$last"

I assume the following layout for test.txt:

firstdirectory lastdirectory

This solution has problems when the first directory string contains whitespaces as read uses them as a separator. It is just an example to start with.