How do I code switches with the dash in bash shell scripts?

So I'm writing a bash shell script for launching dockers to control whether they are interactive or persistent after instantiating, and give them a name. In the command line I will include the switches to do this, like foo.sh --rm -it project1 and my bash script is:

#!/bin/bash
#Accepts specific switch values
#remove docker upon exit -> use --rm in first position
remove=$1
#open up docker in interactive shell --> use -it in second position
interactive=$2
#pass a name for the project --> pass the name in the third position. No name = projectA
named=$3
workdir="/home/s589/Desktop/WORMHOLE"
datadir="/home/s589/Desktop/celeba"
if ["$named" = ""]; then
named="projectA"
fi
docker run --gpus all -it -p 8888:8888 --ipc=host --shm-size 24G "$remove" "$interactive" --name="$named" \ -v $workdir:/workspace \ -v $datadir:/workspace/celeba \ fastai:1.0.34

Of course if I pass the wrong thing it doesn't work, so I would have to write error correction. Isn't there a more elegant way to do this?

2 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like