Home > Software design >  error in executing interactive bash script to run docker containers
error in executing interactive bash script to run docker containers

Time:06-18

Hello guys i am new in shell scripting and I tried run the script below but have following error message:

#!/bin/bash

echo "Enter the name of the image whose container you want to run: "
read container
echo "Enter a name for this container: "
read name
echo "do you want to run in detatch mode? "
read d
if [ $d -eq yes ]
then
docker run --name $name -P -d $container
elif [ $d -eq no ]
then
docker run --name $name -P $container
else
echo "invalid input"
fi

This produces the following error messages:

./main.sh: line 9: [: yes: integer expression expected
./main.sh: line 12: [: yes: integer expression expected

CodePudding user response:

-eq compares two integers use = in order to compare two strings for more info please refer to: https://stackoverflow.com/a/20449556/9881735

for example:

 [ $d = "yes" ]
  • Related