[Solved] Nested If

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] Nested If
# 1  
Old 03-10-2014
[Solved] Nested If

I am having a problem with a nested if. I am sure I am overlooking something. I check for the existence of $Pidfl3 and it exists, o this condition I then want to check for the existence of a next file and remove it. The first if is executed, but on the second if I get test: argument expected.

My Code

        if [ -f $Pidfl3 ]

          if [ -f $Pidfl ]
            rm "$Pidfl" 
          if [ -f $Pidf2 ] 
            rm "$Pidfl2" 


Can anybody help?

Last edited by Charles Swart; 03-10-2014 at 09:03 AM.. Reason: Code tag
# 2  
Old 03-10-2014
Check your script whether variable is assigned value before you use it in If
# 3  
Old 03-10-2014
try double square braces

if [[ -f ${Pidfl3} ]]
  if [[ -f ${Pidfl} ]]
    rm "${Pidfl}" 
  if [[ -f ${Pidf2} ]] 
    rm "${Pidfl2}" 

This User Gave Thanks to SriniShoo For This Post:
# 4  
Old 03-10-2014
Double Square

Thank you

The double square brackets did the trick. As being new to scripting I am curious as to why?

# 5  
Old 03-10-2014
Click here to know more about this.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nested if else

Hi, i m trying to create script which logic is like below. if ; then x=`cat /tmp/testoutput.log | grep STOP | wc -l` y=`cat /tmp/testoutput.log | grep RUN | wc -l` if ; then echo "process stop" if ; then echo "process running " else echo "file not found" fi ----------------... (2 Replies)
Discussion started by: tapia
2 Replies

2. Shell Programming and Scripting

two while nested loops

for server in $(echo `cat /tmp/ScanHosts_${USERSNAME}.TXT`) do for portnumber in $(echo `cat /tmp/ScanPorts_${USERSNAME}.TXT`) do #echo ${server} ${portnumber} ... (3 Replies)
Discussion started by: SkySmart
3 Replies

3. Shell Programming and Scripting

nested if else -error

HI everyone, I am not able to find error in the script, when i run the script till line No. 20 i.e, read var4 everything runs fine. After that the script exits out. #!/bin/bash echo -e "Want dryrun OR merge: \n " read var1 if ] ; then echo -e "\n Please select from the given... (10 Replies)
Discussion started by: rishi.aradhya
10 Replies

4. Shell Programming and Scripting

Nested if loop

Hi Team, I just want to check whether my nested if loop used is correct or not. if ] if ] export1 else export2 fi else if ] export3 else export4 fi fi Thanks Shiva (5 Replies)
Discussion started by: shivashankar_S
5 Replies

5. Shell Programming and Scripting

Nested case

Hi there, I have nested case in my script. I am asking user, want to continue? if user press y/Y then my inner case should continue, rather than that my code start from beginning. I would like to continue my inner case until user press n or N. Is any one tell me how can I do? Thanking You,... (2 Replies)
Discussion started by: kasparov
2 Replies

6. UNIX for Dummies Questions & Answers

Nested If in Unix

Hi!! LookVar=`find . -name "${input}" | wc -w` if then cd $input rm -f * ftp -n -i $HostName << EOF quote USER $User quote PASS $Password cd $Path SoLookVar=`find . -name "${input}" | wc -w` echo $SoLookVar if then cd $input mget ./* bye EOF chmod 775 ./* (12 Replies)
Discussion started by: Afsana
12 Replies

7. Programming

Help nested sql

Hi, I bought a module called "Price comparison listing" for Prestashop that was supposed to help me push product listing to kelkoo. Unfortunately it doesnt work and the developers don't fix, and they don't refund.... I have reported this to prestashop, but I need a solution.. Be careful buying... (1 Reply)
Discussion started by: joje47
1 Replies

8. Shell Programming and Scripting

[solved] merging two files and writing to another file- solved

i have two files as file1: 1 2 3 file2: a b c and the output should be: file3: 1~a 2~b 3~c (1 Reply)
Discussion started by: mlpathir
1 Replies

9. Shell Programming and Scripting

nested variables

Is there any way to do variable nesting using sh? For example: example_1="a test string" example_2="another test" example_3="etc..." i=2 echo ${example_$i} The shell reports: sh: ${example_$i}: bad substitution If not, maybe someone could suggest another method. Thanks in... (3 Replies)
Discussion started by: kevinl33
3 Replies
Login or Register to Ask a Question