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.
]sedcdcommand since it will fail after first iteration.sedto work on, so it will fail because the-ioption cannot rename standard input. If you must usecd, use a sub-shell:( cd "$dirs/"; ... )so that when the sub-shell is complete, the original shell hasn't changed directory (so you cancdto another directory). You might do better withfor dirs in */Seadont, too.