problem in exit in same shell with echo


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem in exit in same shell with echo
# 1  
Old 07-20-2012
problem in exit in same shell with echo

Hello All,

I am in SunOS usvh3eudv80 5.10. facing problem in my script:

Code:
#!/bin/bash
var1=`date +"%m%d%H%M"%S.zip`
 
echo " Hi your current dir is :---> $(pwd)";echo " Changing to home dir:"
 
cd ~ 2>/dev/null || {echo "Change dir failed ....Quiting...." && exit 2 }; ls -lrt
 
echo "..... APPLICATION logs....."

Here I want to check if cd fails then echo the msg and exit the script. But when I try to group with { } it says :

Hi your current dir is :---> /home/tomcat1/Release_Inte
Changing to home dir:
./appslogs_bks.sh: line 9: syntax error: unexpected end of file

When i use () then it is not exiting as it executes in subshell.

How to exit in same shell. Pls let me know if I am not clear ..

Thanks
Krsna..
# 2  
Old 07-20-2012
Why not just use a simple test?

Code:
#!/bin/bash
var1=`date +"%m%d%H%M"%S.zip`

echo " Hi your current dir is :---> $PWD"
echo " Changing to home dir:"

cd ~ 2>/dev/null
if [ $? -ne 0 ]; then
  echo "Change dir failed ....Quiting...."
  exit 2
fi

ls -lrt

echo "..... APPLICATION logs....."

# 3  
Old 07-20-2012
Or try like this:

Code:
cd ~ 2>/dev/null || { echo "Change dir failed ....Quiting....";exit 2; };ls -lrt

# 4  
Old 07-20-2012
problem in exit in same shell with echo

Hi Scott,

Thanks, I knew that but just what to write in one line ....

Hi Elixir,
Smilie
Your solution is pefect working fine. But wanted to know is any way to execute such command in same current shell. I thought just by grouping by {} it will do..

Thanks
Krsna...

---------- Post updated at 02:53 AM ---------- Previous update was at 02:51 AM ----------

Sorry Elixir,

i think you have already answered..

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

cmd || echo "something" - doesn't exit uppon error

Hi guys, I have a shell script where I have the following: for i in ad0 ad1 do gpart create -s gpt $i || echo "Cannot create GPT partition on "$i". Exiting ..." gpart add -s 128 -t freebsd-boot $i || echo "Cannot add freebsd-boot partition on "$i". Exiting ..." gpart add -s 4G -t... (2 Replies)
Discussion started by: da1
2 Replies

2. Shell Programming and Scripting

echo and exit from makefile

I have a make file that needs to have allot of options set. Some of these are based on uname and such, some are passed in the call to make. I need to add an else that will print to the shell and exit under some circumstances. ifeq "$(cmp)" "g44" CC++ = g++ else @echo... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

3. Shell Programming and Scripting

echo problem

hi all i have little problem below is my shell script a=`sqlplus fss_cst/fss_cst@dolp1 << EOF SET PAGESIZE 0 FEEDBACK OFF TRIMOUT ON; select process from lfs$ta_process where valid_to_dat=to_date('9/16/2010','mm/dd/yyyy'); EOF` echo ${SQL} the script name is test2.sh when i execute... (5 Replies)
Discussion started by: aishsimplesweet
5 Replies

4. Shell Programming and Scripting

Problem using exit(1)

Hi All, i have a script named as 1. scr_FTP.sh, it calls the script(2) 2. file_create.sh And in that 2nd script, i use the below function run_complete_workflow(). I introduced exit(1) to exit from the function: run_complete_workflow() and also from the 2nd script: file_create.sh and... (3 Replies)
Discussion started by: vsmeruga
3 Replies

5. Shell Programming and Scripting

problem in exit status of the command in a shell script-FTP

Hi All, I have developed below script for FTP a file from unix machine to another machine. ftpToABC () { USER='xyz' PASSWD='abc' echo "open xx.yy.zbx.aaa user $USER $PASSWD binary echo "put $1 abc.txt" >> /home/tmp/ftp.$$ echo "quit" >> /home/tmp/ftp.$$ ftp -ivn <... (3 Replies)
Discussion started by: RSC1985
3 Replies

6. Shell Programming and Scripting

Problem with echo *

Hello all, Please help with the below. I have a requirement where in I have to read a pattern and print it as shown below. Patterns will be as below. Input Output Pattern Should be printed as below with spaces such that I can awk. -*--* - * - - * *--**... (2 Replies)
Discussion started by: tenderfoot
2 Replies

7. UNIX for Dummies Questions & Answers

echo $ problem

Hi I am using tcsh. I want display in a file_1 like this. $VARIBALE I gave in a termianl > echo "\$VARIBALE" > file_1 Its not workning. It was giving VARIBALE: Undefined variable. I gave \ before $, but why it was giving undefined varible? Please help me. Thanks in advance (4 Replies)
Discussion started by: chaitubek
4 Replies

8. Shell Programming and Scripting

echo problem

echo "XXXXX" >> /xx/output.txt cat /xx/file.txt| awk '{tony=tony+$1+$2; print tony/$3*100}' >> /xx/output.txt Dear all, In this situation i will have 2 lines in the output file. What i want is to have only one output line. e.g: XXXXX "value" HOW to put the output of the "cat and awk" in... (1 Reply)
Discussion started by: tontal
1 Replies

9. Shell Programming and Scripting

echo problem

Hi, I have given the following statement in a script to put the values of variables (VAR1, VAR2,...) in a file. echo " $VAR1 $VAR2 $VAR3 $VAR4 $VAR5" >> filename But the output is not coming properly. Variables VAR5, VAR4 are replacing the first (VAR1, VAR2,..). I can't... (5 Replies)
Discussion started by: abrd600
5 Replies

10. UNIX for Dummies Questions & Answers

`echo` problem.

Have the following lines in a script: echo "-----------------------------------------------"\ "---------------------" >> $xdfrpt echo "- Date - - / - /stand - /u - /u1 - /u2 -"\ "/x1 - /x2 - /x3 -" >> $xdfrpt echo... (1 Reply)
Discussion started by: Cameron
1 Replies
Login or Register to Ask a Question