Welcome to the Linux Foundation Forum!

Working on a Bash Script

bfpa40
bfpa40 Posts: 2
edited October 2023 in Command Line/Scripting

I have the following bash script that is working. However I want to enter an argument as i execute the script like so: ./test.sh pdj1compC So it will use that argument and NOT print out the echo statement when it gets down to that line of the script for just that one item all the others will print out. This is a test script ill build off to conduct a certain job so as it is its goofy I know. I just need assistance to get me over this mental block im having. Thank You

Here is the script:

!/usr/bin/bash

n="1 2 3 4 5 6"

m="compA compB compC compD"

echo " Do you wish to logoff all the computers is so enter y otherwise just press Enter"

read logoff

if [ $logoff == y ]

then

for j in $n

do

for k in $m

do echo "Hello there this is Comjputer pdj$j$k ; whoami "

done

done

else

echo "Returning to prompt"

fi

echo "This script is complete"

Categories

Upcoming Training