0

I have the following command

echo “more PHONEBOOK.lst | awk '!/ NY /' | sort -k1 | sort -k4 | tee PHONENOTNY.LST” >> NOTNY.sh && chmod 0777 NOTNY.sh 

However when I run the command and view the content of NOTNY.sh it contains

“more PHONEBOOK.lst

It should contain

more PHONEBOOK.lst | awk '!/ NY /' | sort -k1 | sort -k4 | tee PHONENOTNY.LST

How do I copy the text from the command and not the result I am getting?

  • 4
    I'm guessing those are "smart" quotes, which your shell saw as just more bytes instead of actual quotes. – Jeff Schaller Oct 15 '17 at 22:03
  • How do I make it see the command as a whole and not evaluate the command? – John Hamlett IV Oct 15 '17 at 22:11
  • 2
    Quote the string. Your example contains the characters and (U+201C and U+201D) which are not quotes as far as the shell is concerned. The shell understands ' (U+0027) and " (U+0022). The fancy curly characters featured in your example are just ordinary fancy curly characters. – AlexP Oct 15 '17 at 23:11
1

Instead of “smart” quotes, use normal "double-quotes":

printf "%s\n" "more PHONEBOOK.lst | awk '!/ NY /' | sort -k1 | sort -k4 | tee PHONENOTNY.LST" >> NOTNY.sh && chmod 0777 NOTNY.sh 

Or, saving a pointless call to more, since awk will read the files you tell it to:

printf "%s\n" "awk '!/ NY /' PHONEBOOK.lst | sort -k1 | sort -k4 | tee PHONENOTNY.LST" >> NOTNY.sh && chmod 0777 NOTNY.sh 

Or, since the second sort will just override the first one:

printf "%s\n" "awk '!/ NY /' PHONEBOOK.lst | sort -k4 | tee PHONENOTNY.LST" >> NOTNY.sh && chmod 0777 NOTNY.sh 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.