Reputation: 25
I have a bash script that isn't properly working, I am new to this type of coding. Any suggestions or help would be great.
I am attempting to change email addresses of an old user with a new user across our PuTTy platform. However not all directories have a certain file, I think there may be a problem with my IF statement. Here is the script I have attempted using:
#!/bin/bash
#set -x
for dirs in *
do
echo $dirs
cd $dirs/
if [ -d "Seadont"]
then
sed -i 's/USER1/USER2/g'
ls
fi
done
My results are not correct.
Upvotes: 1
Views: 78
Reputation: 7959
Try this:
#!/bin/bash
#set -x
for dirs in * ;do
echo $dirs
if [ -d "Seadont"] ;then
sed -i.bak 's/USER1/USER2/g' $dirs
fi
done
Mind you that it won't work if there are white spaces on "$dirs". I can propose a better solution if it does, but I would need to know current directory.
Upvotes: 1