ksh case statement issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh case statement issue
# 1  
Old 02-02-2017
ksh case statement issue

Hi. I wrote the following case statement to replace a series of 'ELIF' statements as it looks better and is easier to maintain. However, for some reason the commands don't fully work in this format. Take option 1. It should call a script that runs in the background but it doesn't work. Can anyone see what I'm doing wrong?
Many thanks.

Code:
case ${_OPTION} in
                  1) print "Running option 1: $file\n"; $(nohup ${BASE}/run_test ${file} > /dev/null 2>&1 &) ; _RC=$? ; [[ $_RC -ne 0 ]] && exit 1
                        ;;
                  2) print "Running option 2: $file\n"; ${BASE}/run_test ${file}; _RC=$?; [[ $_RC -ne 0 ]] && exit 1
                        ;;
                  3) print "Running option3"
                        ;;
                  *)
                        print "[ERROR] Invalid number specified. Exiting ...\n "; exit 1
                esac

# 2  
Old 02-02-2017
Code:
1) print "Running option 1: $file\n"; { nohup ${BASE}/run_test ${file} > /dev/null 2>&1 ; } & ; _RC=$? ; [[ $_RC -ne 0 ]] && exit 1";";";

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 02-02-2017
... or perhaps this:-
Code:
                  1) print "Running option 1: $file\n"; (nohup ${BASE}/run_test ${file} > /dev/null 2>&1) & _RC=$? ; [[ $_RC -ne 0 ]] && exit 1

I've dropped the leading $ from $(nohup and changed the trailing &) ; to be ) &


I assume that you just want to know that the task launched in the background successfully, not that the task finished successfully.



Robin
These 2 Users Gave Thanks to rbatte1 For This Post:
# 4  
Old 02-02-2017
Thanks guys. Both methods worked!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with while/case statement.

Hi, In my script I have while loop with case statement its working fine, I have added two more arguments as input to script. So i have addedd 2 cases in the existing case statement. -a and -d are newly added blocks. Am passing the arguments for the same as below. test.sh -s NY -t N -f... (4 Replies)
Discussion started by: shieksir
4 Replies

2. Shell Programming and Scripting

Using an array with a case statement in KSH

Hi, I'm really new ro shell scripting (actually any kind of programming) and am pretty sure I'm making a pretty basic error here but I can't for the life of me figure it out. What I'm trying to do is get an array working with a case statement in a KSH script. The code is as follows: ... (3 Replies)
Discussion started by: SReilly
3 Replies

3. Shell Programming and Scripting

Case statement

Hello, The standard case statement :- case "$1" in "IE0263") commands;; "IE0264") commands;; esac is it possible to have :- case "$1" in "IE0263" OR "IE0878") commands;; "IE0264") commands;; esac Thanks (4 Replies)
Discussion started by: jmahal
4 Replies

4. Shell Programming and Scripting

ksh "case" statement question

Hi I have the following case statement: case $larg in *_* ) a=${larg%_*}; b=${larg#*_}; ;; *^* ) a=${larg%^*}; b=${larg#*^}; ;; esac I cannot figure out what *_* and *^* stand for... Also what a=${larg%_*}; b=${larg#*_}; and a=${larg%^*}; b=${larg#*^}; ... (1 Reply)
Discussion started by: aoussenko
1 Replies

5. Shell Programming and Scripting

help with case statement

I am writing a script to pull diskspace information from our servers. Here is the script that I wrote: #!/bin/ksh for host in `cat /oper/hosts/esc.misc` do ssh -q -o ConnectTimeout=10 operator@$host df -h|grep "/dev/" |egrep '8%|9%|100%' | awk '{print H " " "at " $5 " with " $4 "... (1 Reply)
Discussion started by: rkruck
1 Replies

6. UNIX for Dummies Questions & Answers

case statement in UNIX scripting (ksh)

Hi, I have a script like below : #!/bin/ksh echo "Do you want to export all docs ?" read alld echo "Do you want to export template or report only " read temr case && ] #arguments ;; case && ] #arguments ;; case && ] #arguments ;; (4 Replies)
Discussion started by: luna_soleil
4 Replies

7. Shell Programming and Scripting

ksh case statement

I am trying to write a ksh script using the case statement to select certain directories to remove. The directories that I am looking for are in the following format 2008-10-10. I want to exclude all other files/directories that contain anything other the 4 digit year,a dash, 2 digit month, a... (2 Replies)
Discussion started by: dgilc
2 Replies

8. UNIX for Dummies Questions & Answers

CASE statement

Hi, I am writing a bash shell script. My script has a few user defined parameters. When the script runs the first thing it does is make sure that these parameters are valid. One of the parameters is called YEAR. A valid input for YEAR can be 1997-2000. One way I have come up with to ensure... (3 Replies)
Discussion started by: msb65
3 Replies

9. Shell Programming and Scripting

case statement

Hi all, I think i'm asking a sqtupid question here.. i'm using case sttament, what is the syntax or symbol for "or"? I thought was || here a quick sample of my case statment echo "Would you like to update your detail ?" read response case $response in ... (2 Replies)
Discussion started by: c00kie88
2 Replies

10. Shell Programming and Scripting

case statement

Hi all, is it possible to create a 'dynamic' case statement. ie select option in `ls` do case satement depending on results of the above `ls` done I hope I have explained this ok! Thanks Helen (1 Reply)
Discussion started by: Bab00shka
1 Replies
Login or Register to Ask a Question