I have a bash script which runs some jobs. Sometimes I want to be able to run those jobs with nice
to lower their priority on a server.
For example, if my executable is a.out
, I can run from the terminal nice a.out
to lower the job priority.
In my bash script I have a variable NICE
. I do one of the following 2 things:
# either nice is set
NICE="nice"
# or it is left unset
NICE=""
I then run my job using
"$NICE$ ./a.out
later in the script.
This works when NICE="nice"
however does not work when NICE
is left set to NICE=""
.
One way around this is to use an if statement:
if [ "$NICE" == "nice" ]
then
nice ./a.out
else
./a.out
fi
But this becomes 5 or 6 lines of code rather than just a single line.
Is it possible to accomplish what I was attempting using NICE
as a variable to launch an executable with niceness or no niceness?