0

Goal

My server manages jobs using SLURM. Each job in the queue has a job ID, which can be either a single integer or two integers separated by an underscore, e.g., 123_4. You can use scontrol show job [job ID] to print some general info about the job, including the name of the file that stores the standard output (specifically, there is a line that says StdOut=/path/to/stdout/file). All I want to do is write an alias that takes the ID from the terminal input and opens this file in vim.

My attempt

alias checkout='vi $(scontrol show job $1 | grep StdOut | cut -d'=' -f 2)

The problem

When I try checkout 123_4, the script ignores the _4 part. This is a problem because in practice, this part is the array ID, and there will be many jobs in a single array. Hence, scontrol will print a bunch of StdOut=... lines, and vim will open a bunch of files (for jobs 123_1, 123_2, etc.). The issue must be in how $1 reads in the terminal input, but I couldn't figure out how to fix that. For example, I tried replacing it with $@ and $*, and doing something like "${1}" to no avail.

I figure this should be an easy fix for anyone more experienced with bash!

Jamin
  • 1
  • 1
    Aliases don't take positional parameters like $1 - I suspect what's really happening is that $1 is expanding to an empty string, and you're running scontrol show job without a job ID, which is therefore listing all jobs by default. – steeldriver Jun 19 '23 at 13:28
  • Use a shell function instead of an alias to handle arguments. Your code seems to have problems with quoting. There is an odd number of single quotes. – Bodo Jun 19 '23 at 13:31

0 Answers0