I know that similar questions to this have been asked, but I haven't found one that addresses my situation closely enough...
I need to time a command in a bash script, similar to this:
mytime="$(time ( ls ) 2>&1 1>null)"
rm null
This works fine. But when I try to replace ls with something more complicated, I run into issues:
command="$reg 1d_euler_2nd.rg -nc $nc -ll:cpu $np -ns $nstop"
mytime="$(time ( $command ) 2>&1 1>null)"
rm null
where reg is an environment variable and nc, np, and nstop are all defined in my script. I get the following error when I try to use this code:
(standard_in) 1: syntax error
(standard_in) 1: illegal character: :
(standard_in) 1: illegal character: :
(standard_in) 1: illegal character: $
(standard_in) 1: syntax error
(standard_in) 1: illegal character: :
(standard_in) 1: syntax error
(standard_in) 1: syntax error
(standard_in) 1: illegal character: :
Any help would be greatly appreciated!
My apologies -- as I was trying to create a minimal working example, I realized that the problem was elsewhere in my code.
nullbefore you delete it or do you just mix it up with/dev/null? What does "where reg is an environment variable" mean? What is the content?reg,ncetc. might contain.bash -vx script.shand add the output to your question. I am not sure which program produces the error messages.