Skip to main content
oops, need to quote the variable that's being expanded
Source Link
Sotto Voce
  • 7.3k
  • 1
  • 14
  • 29

Here's the general approach:

#!/bin/bash out_file=$(basename "$0") echo sbatch --gpus=1 -p long -o err_$"err_${out_file%.*}.outout" 

If that outputs the sbatch command you're trying for, then remove the echo and give it a try.

A couple of comments:

  • 99% of the time you don't want a shell that's running your script to behave as a login shell, so I removed the -l option from the top line.
  • The $( ... ) method of capturing the output of a command is usually better than the old-style method that uses backticks/backquotes. There are many fewer problems with special characters and nesting one capture within another.
  • You had the right idea about how to strip trailing characters from the $out_file variable, I was lazy and didn't test your expression, instead I replaced it with one I use a lot, and is somewhat simpler.

Here's the general approach:

#!/bin/bash out_file=$(basename "$0") echo sbatch --gpus=1 -p long -o err_${out_file%.*}.out 

If that outputs the sbatch command you're trying for, then remove the echo and give it a try.

A couple of comments:

  • 99% of the time you don't want a shell that's running your script to behave as a login shell, so I removed the -l option from the top line.
  • The $( ... ) method of capturing the output of a command is usually better than the old-style method that uses backticks/backquotes. There are many fewer problems with special characters and nesting one capture within another.
  • You had the right idea about how to strip trailing characters from the $out_file variable, I was lazy and didn't test your expression, instead I replaced it with one I use a lot, and is somewhat simpler.

Here's the general approach:

#!/bin/bash out_file=$(basename "$0") echo sbatch --gpus=1 -p long -o "err_${out_file%.*}.out" 

If that outputs the sbatch command you're trying for, then remove the echo and give it a try.

A couple of comments:

  • 99% of the time you don't want a shell that's running your script to behave as a login shell, so I removed the -l option from the top line.
  • The $( ... ) method of capturing the output of a command is usually better than the old-style method that uses backticks/backquotes. There are many fewer problems with special characters and nesting one capture within another.
  • You had the right idea about how to strip trailing characters from the $out_file variable, I was lazy and didn't test your expression, instead I replaced it with one I use a lot, and is somewhat simpler.
simplifying my wording
Source Link
Sotto Voce
  • 7.3k
  • 1
  • 14
  • 29

Here's the general approach:

#!/bin/bash out_file=$(basename "$0") echo sbatch --gpus=1 -p long -o err_${out_file%.*}.out 

If that outputs the sbatch command you're trying for, then remove the echo and give it a try.

A couple of comments:

  • 99% of the time you don't want a shell that's running your script to behave as a login shell, so I removed the -l option from the top line.
  • The $( ... ) method of capturing the output of a command is usually better than the old-style method that uses backticks/backquotes. There are many fewer problems with special characters and nesting one capture within another.
  • You had the right idea about how to strip trailing characters from the $out_file variable, I was lazy and didn't test your expression, instead I replaced it with this one I use a lot, whichand is somewhat simpler.

Here's the general approach:

#!/bin/bash out_file=$(basename "$0") echo sbatch --gpus=1 -p long -o err_${out_file%.*}.out 

If that outputs the sbatch command you're trying for, then remove the echo and give it a try.

A couple of comments:

  • 99% of the time you don't want a shell that's running your script to behave as a login shell, so I removed the -l option from the top line.
  • The $( ... ) method of capturing the output of a command is usually better than the old-style method that uses backticks/backquotes. There are many fewer problems with special characters and nesting one capture within another.
  • You had the right idea about how to strip trailing characters from the $out_file variable, I didn't test your expression, I replaced it with this one, which is somewhat simpler.

Here's the general approach:

#!/bin/bash out_file=$(basename "$0") echo sbatch --gpus=1 -p long -o err_${out_file%.*}.out 

If that outputs the sbatch command you're trying for, then remove the echo and give it a try.

A couple of comments:

  • 99% of the time you don't want a shell that's running your script to behave as a login shell, so I removed the -l option from the top line.
  • The $( ... ) method of capturing the output of a command is usually better than the old-style method that uses backticks/backquotes. There are many fewer problems with special characters and nesting one capture within another.
  • You had the right idea about how to strip trailing characters from the $out_file variable, I was lazy and didn't test your expression, instead I replaced it with one I use a lot, and is somewhat simpler.
Source Link
Sotto Voce
  • 7.3k
  • 1
  • 14
  • 29

Here's the general approach:

#!/bin/bash out_file=$(basename "$0") echo sbatch --gpus=1 -p long -o err_${out_file%.*}.out 

If that outputs the sbatch command you're trying for, then remove the echo and give it a try.

A couple of comments:

  • 99% of the time you don't want a shell that's running your script to behave as a login shell, so I removed the -l option from the top line.
  • The $( ... ) method of capturing the output of a command is usually better than the old-style method that uses backticks/backquotes. There are many fewer problems with special characters and nesting one capture within another.
  • You had the right idea about how to strip trailing characters from the $out_file variable, I didn't test your expression, I replaced it with this one, which is somewhat simpler.