I'm developing a script which will have a lot of options to be checked for and will be setting things / doing further things accordingly.
I'm using a LOT of nested if, elif, else throughout my script. In some cases 5 to 6 levels deep. I'm facing some very basic problems. I've torn my hair, but am unable to understand what's wrong here.
If I run this through SH or BASH, it gives me an error on line 23
If I run this through a shell based on ZSH (our product is based on this and this is what I would be finally running the script on), I get this:
Funny part is, if I remove the last 3 lines, (below), the script runs in our ZSH based shell but still gives the same error via BASH. But not sure how it's doing that as the number of fi's don't match the number of if's.
Some help / explanation here? Am I missing something very obvious? Or probably is my understanding of nested if else incorrect?
You're missing a "then" after this line:
It's easy to test a script before you run it:
and the nature of the error suggests a problem with the "if" part.
It's also good practice to double-quote variables (whether they need them or not), and there's a useful hint there too about replacing the old `...` command substitution with the newer $(...) one.
Hello experts,
I am having problems with ELIF.
Please see the below code :
read a;
read b;
read c;
if || || ; then
echo "EQUILATERAL"
elif || || ; then
echo "SCALENE"
else
echo "ISOSCELES"
fi
This code works fine for the EQUILATERAL case but fails completely for the... (5 Replies)
Hello all,
I have a scenario where I take user input values and accordingly take actions
say I run a script with
sh scriptname -x GB -e txt (txt can also be text)
I have used if clause for the first input (-x GB)and it is working fine
Now for second the scenario is
if
then
echo... (3 Replies)
Hi all,i have configured the following script to check if the file exists or not,
#!/bin/sh
sleep 30
{
FILEFULL=$1`date +$2`*
if ;
then
echo $FILEFULL exist
else
echo "$FILEFULL File not Found" | mail -s 'server' myaccount@mydomain.com
fi
}
but i have a problem, i need to... (2 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
This is my problem for the class.
Write a script that asks for the user's age. If it is equal to or higher... (6 Replies)
I have a array reference which has some number of array references inside it.The nested array references also contains the array references.
my $Filename = "sample.xml";
my $Parser = new XML::Parser( Style => 'tree' );
my $Tree = $Parser->parsefile( $Filename );
Here the $Tree is the... (6 Replies)
Please see the following script.
basic="a b c"
advance="d e f"
A="basic advance"
for g in $A
do
echo $g
done
The result would be obviously
basic
advance
I want to ask how can i get the following result using $A in for loop
a
b
c (5 Replies)
count2=0
var2=NOT
if
then
echo"Loop1"
command="egrep ',$var1,"
if
then
echo "the command is OR"
command=$command"|,$var3,"
echo "$command"
elif
then
command=$command"| egrep ',$var3,"
else
... (4 Replies)
Hey, I'm writing this bash script that will test print me many copies of the same program but with different combos of 4 variables being between 1 and 100. Here's the code:
#! /bin/bash
x=0
for ((a=1; a < 101; a++))
do
for ((b=1; b < 101; b++))
do
for ((c=1; c < 101; c++))
do
for... (4 Replies)
hi everybody:
could anybody tell me what I'm doing wrong. I've tried to nest if staments like this:
if condition1]; then
if condition2];then
if condition3];then
commands
else
commands
fi
elif condition4];then
commands... (3 Replies)
Hi all,
I got some problems on executing the following scripts.
Scripts:
if ]; then
echo "M${str}O 0 1" >> ${tempFile}
elif ]; then
echo "M${str}O 1 0" >> ${tempFile}
else
echo "M${str}O 0 0" >> ${tempFile}
fi
Error:
"`;' is not expected."
what's the problem? (2 Replies)