You need either a here document or a here string.
bsub <<HEREDOC
$(script.bsub 1)
HEREDOC
That's what a here document looks like. The shell will read in the expansion of everything between the line in which <<HEREDOC
occurs until it finds a line on which nothing but HEREDOC
occurs and pass the output to the invoked command on its file descriptor 0 - stdin.
A here string is the same thing in principle:
bsub <<< script.bsub 1
It may look simpler to use, but it's also easier to confuse and it is not portable shell script. While a here document is defined as part of the POSIX shell standard, a here string is a shell specific implementation - though it will work in bash.
It is probably best to use a here document in every scripted case unless you can be 100% certain that the script will never be run in an environment in which it doesn't break, and to use here-strings only in interactive use as they are little more than a shortcut in the first place.
Of course, if either of those work, then probably:
script.bsub 1 | bsub
would do as well. That will |pipe
script.bsub
's stdout into bsub
's stdin, but it will also very likely run bsub
in a subshell. If bsub
modifies the current shell environment in any way - such as altering the value of a shell variable - that is depended upon, the |pipe
may not be the best solution.
I'd try to use bash variable substitution:
test)
shift
docker exec -it $(docker-compose ps -q web) python manage.py test "${@-apps}"
;;
Other way is to check $*
instead of $1
:
case $* in
bash)
...
test)
docker exec -it $(docker-compose ps -q web) python manage.py test apps
;;
test\ *)
docker exec -it $(docker-compose ps -q web) python manage.py test "${@:2}"
;;
Best Answer
Modifying your original script:
The standard parameter expansion
${var:+word}
will expand toword
if the variablevar
is set and not empty. In the code above, we use it to add--enhancement "$2"
to the command if$2
is available and not empty.I've also taken the liberty to assume that what you are giving to
--snr
as an option-argument should be the loop variable's value.My personal touch on the code (mostly just using
printf
rather thanecho
, avoiding long lines, and giving the code a bit more air):As mosvy points out in comments below: If your
/bin/sh
happens to be thedash
shell, or some other shell that does not properly resetIFS
as a new shell session starts (this is required by POSIX), and if you have, for one reason or other, exportedIFS
and given it a non-default value, then you may want to useunset IFS
at the top of the above script.Do that whenever you have fixed all other issues that exporting
IFS
doubtlessly have raised (don't exportIFS
).