Hi Experts
I am executing below script where running 3 sed commands over array and getting the status of each commands if any sed fails then it should exit ,need your help to make below work
Getting below error as of now
sed: -e expression #1, char 0: no previous regular expression
Command 'sed -i s///g .abc' failed with exit code 1
CODE
#!/bin/bash
E=java6
F=java7
cd /tmp/dd
Declare an array of commands
commands=("sed -i "s/${E}/${F}/g" "abc"" "sed -i "s/${G}/${H}/g" "pqr"" "sed -i "s/${G}/${H}/g" "xyz"")
Iterate over the commands array
for cmd in "${commands[@]}"
do
# Execute each command and store its exit status
$cmd
status=$?
# Check the exit status
if [ $status -ne 0 ]; then
echo "Command '$cmd' failed with exit code $status"
exit 1
fi
done
echo "All commands completed successfully"
exit 0