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
-loption 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_filevariable, I was lazy and didn't test your expression, instead I replaced it with one I use a lot, and is somewhat simpler.