You are not logged in.
I'm trying to run this command and put an apostrophe at the beginning:
echo test | awk '{ system("echo '"'"' " $var) }'
However
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
But I wanted:
'test
For example, when i run this command:
echo test | awk '{ system("echo '"e"' " $var) }'
Results:
e test
How can i add a single quote at beggining?
Last edited by Plup (2019-05-14 23:42:11)
Offline
echo test | awk '{ printf "\047"; system("echo " $var); }'
But why are you using system("echo ...") in the first place?
echo test | awk '{ printf "\047%s\n", $var; }'
Last edited by Trilby (2019-05-14 22:22:59)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I'm a very beginner on script, so it's hard for me to say what could be put in the place of echo and what should be batter. Echo was the closest command that came into my mind.
I traied with printf and tried again with awk, but echo was the closest successful command
Offline
It worked! Thank you, Trilby!
echo test | awk '{ printf "\047%s\n", $var; }'
Offline
Please remember to mark your thread [SOLVED] (edit the title of your first post).
Offline
Also note that '$var' is really just nonsense there that only coincidentally does what you want. There is no variable 'var', but as there is no variable with that name it expands to 0 which then makes that $0 or a reference to the whole line from the stdin. It'd be much more readable (and less fragile) to just explicitly reference $0.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Also note that '$var' is really just nonsense there that only coincidentally does what you want. There is no variable 'var', but as there is no variable with that name it expands to 0 which then makes that $0 or a reference to the whole line from the stdin. It'd be much more readable (and less fragile) to just explicitly reference $0.
This is true, thank you again!
Offline