Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Running call execute_command line with a command that has " " in it

62 views
Skip to first unread message

Pat

unread,
Jul 27, 2022, 1:26:46 PM7/27/22
to
I have a Fortran 90 program that needs to run a bash command in it for text file manipulation.

Unfortunately the compiler gets confused between the "" for the command and the "" for the bash command

Example:
call execute_command_line("cat test.txt | awk '{$1=$NF=""; print $0}' > output.txt")

How do I fix this?

Thanks.

Peter Klausler US

unread,
Jul 27, 2022, 1:36:43 PM7/27/22
to
Replace the two double quotes within the character literal constant with four double quotes: $NF=""""

Pat

unread,
Jul 27, 2022, 1:40:35 PM7/27/22
to
Thanks, it works :)

gah4

unread,
Jul 27, 2022, 1:45:16 PM7/27/22
to
On Wednesday, July 27, 2022 at 10:36:43 AM UTC-7, Peter Klausler US wrote:

(snip)

> Replace the two double quotes within the character literal constant with four double quotes: $NF=""""

Unix is pretty consistent on its quoting conventions, unlike another popular OS.

You have to double quotes as they are seen by the shell, and the double them
as they are seen by awk. Tradition is to run Bourne shell, but otherwise there is still
a shell between you and awk, to process quotes.

If you are using CMD.EXE as your shell, I am much less sure how to do it.

gah4

unread,
Jul 27, 2022, 2:07:46 PM7/27/22
to
On Wednesday, July 27, 2022 at 10:26:46 AM UTC-7, Pat wrote:

(snip)

> call execute_command_line("cat test.txt | awk '{$1=$NF=""; print $0}' > output.txt")

The other complication, which it seems you already figured out,
is that the shell will expand $ variables inside double quotes, but not
single quotes. Combined with awk's use of $, that can be tricky.


dave_th...@comcast.net

unread,
Aug 18, 2022, 1:29:18 AM8/18/22
to
Or more sneakily use the fact that an awk variable (not field) is
implictly initalized to the empty string, plus the default operand for
print is $0 and awk reads files just as well as cat:

...( "awk '{$1=$NF=empty;print}' test.txt >output.txt" )

0 new messages