go to / skip in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting go to / skip in script
# 1  
Old 11-04-2009
go to / skip in script

Hi all
I have some script like this
Code:
#!/bin/bash
mv /tmp/file1 tmp/file2
if [[ $? -eq 0 ]] ; then
  cp /tmp/filetest/ tmp/file3
     if [[ $? -eq 0 ]] then 
      echo "succes"
    else 
      echo "failed"
    fi
else   
 echo "failed"
fi

i didn't try to see if it's work, the thing is that i don't care if it's failed in phase one or two, is there any way to short this written without all this echo
somethis like this
Code:
#!/bin/bash
mv /tmp/file1 tmp/file2
if [[ $? -eq 0 ]] ; then
  cp /tmp/filetest/ tmp/file3
     if [[ $? -eq 0 ]] then 
      echo "succes"
    else 
     go to fail
    fi
else   
 go to fail
fi

fail.
echo "script failed" 
.

or any other way to short this complex script.

thank you very much
best regards

Last edited by Franklin52; 11-04-2009 at 09:38 AM.. Reason: Please use code tags!
# 2  
Old 11-04-2009
Code:
if mv /tmp/file1 tmp/file2 && cp /tmp/filetest/ tmp/file3; then
  echo success
else
  echo failed
fi

# 3  
Old 11-05-2009
Hi
thanks for the response,
According to the syntax if the first command failed
mv /tmp/file1 tmp/file2
it continue to the second command :/tmp/filetest/ tmp/file3.
this is not what i wanted, i need that if the first command, failed ,
it won't continue to the second.
any other idea ?
Best regards.
# 4  
Old 11-05-2009
Quote:
Originally Posted by naamas03
i need that if the first command, failed , it won't continue to the second..
That's what you want... that's what you got Smilie
Learn the difference between && and ||
# 5  
Old 11-05-2009
Like sanmero says this is exactly how && works... Because of efficiency the right side only gets evaluated if the left side is true. If the left side is false it does not matter what value the right side evaluates to, so it never gets evaluated.

S.

Last edited by Scrutinizer; 11-05-2009 at 11:30 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Skip first and last line

Hi All I have a sample file like below: 012312112 1372422843 1236712 1372422843 1275127 3109301010 from which I wan't to: 1.)delete... (10 Replies)
Discussion started by: swasid
10 Replies

2. UNIX for Advanced & Expert Users

Skip files in use

Hi all, i'm trying to configure a script that will find and gzip the searched files, this is easy enough, find /var/log/myfolder/*.log -type f -mtime +1 -exec gzip {} \; cd /var/log/myfolder/ mv *gz myzipped_folder/ but what it would be very handy is to skip the files in use,because tomcat... (13 Replies)
Discussion started by: charli1
13 Replies

3. Homework & Coursework Questions

Unix Script -- To Skip killing a specific process

Hi, By using ps -aux | awk '/mine/{split($15,a,"/");print $1,$2,a}' i get the below listed PID's with there corresponding processes. adm 1522 ABC_Process.tra adm 1939 GENE_Process.tra adm 2729 GENE_Archive.tra adm 3259 xyz_Process.tra I use ps -aux | awk... (5 Replies)
Discussion started by: murali1687
5 Replies

4. Shell Programming and Scripting

How to skip the first line of the script in shell using python?

How to skip first line of the script in shell, using python. (3 Replies)
Discussion started by: KarthikPS
3 Replies

5. Shell Programming and Scripting

Skip first and last n records with awk

Hi, I have an awk code that reads an input file, checks the 4th column and tells if its fine. #!/bin/ksh { if ($4 == 0) print "fine" else print "some problem" }' FILENAME My problem is that, I dont want to check the first 3 and last 3 lines. This can be hard coded by using BEGIN and END... (9 Replies)
Discussion started by: gotam
9 Replies

6. Programming

How to skip getchar in C?

Hi, I would like to read an input from keyboard using getchar. However, if no input (No Carriage return/new line none whatsoever) is given after say, 5 seconds, I would like to skip the getchar and move on. How do I do this in C. I'm using GNU compiler set. Thanks, (5 Replies)
Discussion started by: cprogdude
5 Replies

7. Shell Programming and Scripting

Unix Shell scripting -How to skip User Standard input section from another script

All, problem Description: For example: I have two shell scripts(executables). let name it as script1 and script2.I'm trying to execute script1 from script2. while executing script2, script1 is asking for manual input(input from keyboard). Now i need to know how I can skip this user input... (3 Replies)
Discussion started by: techie99
3 Replies

8. Shell Programming and Scripting

Output of Shell Script Doesn't Skip to next line

Hi. This is what I coded: tput cup $1 $2 # place cursor on row and col tput clear # clear the screen bold=`tput smso` #set stand-out mode - bold offbold=`tput rmso` # reset screen - turn bold off echo $bold # turn bold on tput cup 10 20; echo "Type Last Name:" #bold caption tput cup 12... (3 Replies)
Discussion started by: Ccccc
3 Replies

9. Shell Programming and Scripting

Skip item by using substring

I have a file contents like this.... item1 item2 #item3 item4 #item5 item6 .... I have a KSH script to read this file into an array. I have a for loop which will read each item... I want to be able to skip those item start with # sign as first character in a if condiction inside the... (2 Replies)
Discussion started by: rwunwla
2 Replies

10. Shell Programming and Scripting

Skip new line

Hi, how can I skip the new line of echo? In SH!!!! echo "the date is :" date and result I want is the date is : Tue Oct 11 22:24:37 WEST 2005 I've already tried including the \c inside the echo, but it didn't work. Thanks! (2 Replies)
Discussion started by: pmpx
2 Replies
Login or Register to Ask a Question