I have a command stored in a text file command
which looks like this:
command_name par1 par2 path/with/backslashes -option_1 3 -option_2 0.05 --option_3=* -p 'P001=A' -p 'P002=B' ...
The three dots signify there's a bunch of other parameters of one of the forms above.
It is a lengthy command.
If, on a terminal, I just:
cat command
select the shell
output, paste it and hit enter
, the invoked tool works properly and does what's intended to do.
If, on the other hand, on my bash
shell I type:
$(cat command)
or
$(< command)
Then the tool returns an error, specifically that it cannot find a label:
tool_name: label "A'" not found
So, interestingly, it seems to take the closing quote in the -p 'P001=A'
command option above as part of the label. This got me thinking that maybe there is some subtlety in the cat
output that changes what is passed to the shell
for execution?
If I type (this is bash
):
. command
then again, everything works fine.
The tool can be configured as to output the actual running command, and here's another interesting thing:
The command out of the $(cat command)
line is exactly that of the text file, i.e. the tool outputs something like this:
Commmand line for tool_name version 6.0
----------
command name par1 par2 path/with/backslashes -option_1 3 -option_2 0.05 --option_3=* -p 'P001=A' -p 'P002=B' ...
-----------
All quotes are kept.
On the other hand, if I copy-paste the output of cat command
or I use . command
in the bash
shell, then the same line looks like this:
Commmand line for tool_name version 6.0
----------
command name par1 par2 path/with/backslashes -option_1 3 -option_2 0.05 --option_3=* -p P001=A -p P002=B ...
-----------
The quotes are gone! And the tool works properly.
Any idea about what could be behind this behaviour?
P.S
In case you are wondering why am I doing all this, and not just use . command
, it's because I intend to use this command - as I said it's a lengthy one so I prefer to keep it in a text file - with srun
.
I have a similar approach with other "lengthy commands" and since srun
wants a command line to be fed to it, I use the following template:
srun -p my_queue -option_1 $(cat my_lengthy_cmd) &
This works absolutely fine for other commands/tools. It's only this specific one which is giving me issues.
echo command_name ...
, does the output of$(< command)
look correct? I'm thinking particularly about asterisks expanding into lists of files (or lists of no files). – glenn jackman Dec 15 '23 at 18:59$(cat command)
andset +f
after it, does it help? – icarus Dec 15 '23 at 19:28$(…)
are not special to the shell. – Kamil Maciorowski Dec 15 '23 at 19:59bash < command
orsh < command
? Heck ifsrun
is smart enough to read stdin, evensrun -p my_queue -option_1 < my_lengthy_cmd
– Jim L. Dec 15 '23 at 20:02echo
just before the command itself, the ouptut of$(< command)
is a string where the-p = 'P001=A'
appears, just like the output ofcat
. – Michele Ancis Dec 15 '23 at 21:00set +f;$(cat command);set -f
(that's my interpretation of what you're suggesting) - no luck, same error. – Michele Ancis Dec 15 '23 at 21:02srun -p my_queue -option_1 bash < command
does work!! – Michele Ancis Dec 15 '23 at 21:02set -f; $(cat command)l set +f
. The intention is to suppress the meaning of characters like*
in the output of the cat. – icarus Dec 18 '23 at 22:26