Sponsored Content
Full Discussion: If Error then Exit
Top Forums Shell Programming and Scripting If Error then Exit Post 302674947 by bakunin on Saturday 21st of July 2012 01:21:40 AM
Old 07-21-2012
cd returns - like every other command - an error level you can use: it is stored in the variable "$?", which is updated after every executed command.

A return value of "0" (also: logical TRUE) means success, while values between 1 and 254 (all of them meaning a logical FALSE) show various error conditions.

You can use this in scripts in the following two ways:

Code:
command
if [ $? -eq 0 ] ; then
     echo "success"
else
     echo "some error occurred"
fi

Code:
command && echo "error occurred"

The second variant uses the logical meaning of non-zero being FALSE, the "&&" is a logical "OR": that way, if "command" returns "FALSE", the second command is executed, otherwise not.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Where can I find a list of exit codes? (Exit code 64)

I'm receiving an exit code 64 in our batch scheduler (BMC product control-m) executing a PERL script on UX-HP. Can you tell me where I can find a list of exit codes and their meaning. I'm assuming the exit code is from the Unix operating system not PERL. (3 Replies)
Discussion started by: jkuchar747
3 Replies

2. Shell Programming and Scripting

exit on error - is it possible?

Hi , i have shell scripts that run the mysql directly by echoing and redirecting the output to the mysql logins. whenever the query executes successfully then the script runs fine and nothing has to be done there. Now, when there is an error executing the query then it will generate the error... (8 Replies)
Discussion started by: ahmedwaseem2000
8 Replies

3. UNIX for Advanced & Expert Users

SAM Error non-zero exit status

Our machines HP-UX 10.20 Ace, Attempting to run various areas of SAM such as Backup and Restore, Printers and Plotters any areas of Time, etc give errors like the following: unexpected exit: process /usr/sam/lbin/samx/ -C -p 1358 -s br_sa_bdevs /usr/sam/lib///br.ui exited with a non-zero exit... (0 Replies)
Discussion started by: real-chess
0 Replies

4. Linux

tar error exit delayed form pervious error

Hi when use "tar cpvzf /dev/st0 --exclude=/proc --exclude-/lost+found --exclude=/mnt --exclude=/media --exclude=/sys /" to tape, get the following message "tar: error exit delayed form pervious error", What is the mean ? Please suggest some solution for these errors. thx (1 Reply)
Discussion started by: chayato
1 Replies

5. Shell Programming and Scripting

exit out of a while loop with error

im running a while loop as a file watcher, with incremental counter on the retries..however when the retries reach it's limit i want it exit and echo and error and stop the batch. Im not sure the code i have will do that already... Here is what i have that works: #!/usr/bin/ksh count=0... (2 Replies)
Discussion started by: sigh2010
2 Replies

6. UNIX for Dummies Questions & Answers

aCC exit error

Hi guys I would just like to know if aCC supports the command exit(0); in c++? I am always getting the error below: Error 328: "ac5.C", line 37 # Function 'exit' has not been defined yet; cannot call. exit(0); ^^^^ Anyone had this problem? Thanks! (2 Replies)
Discussion started by: khestoi
2 Replies

7. Shell Programming and Scripting

How to exit a script with error ?

Hi, I have a script ABC which calls another script XYZ. Function of XYZ is to ftp a file from one server to another. code for ABC: #!/bin/ksh PATH=/usr/bin home/user/xyz "$@" exit $? ~ code for xyz: #!/bin/ksh HOSTNAME=$1 SRCNAME=$2 DSTNAME=$3 (4 Replies)
Discussion started by: Salil Gupta
4 Replies

8. Shell Programming and Scripting

FTP exit and error codes

I have a script which connects to a remote server via FTP and gets some file from there. #!/bin/bash /usr/bin/ftp -n remote.hostname.com <<EOF quote USER user123 quote PASS password123 lcd /dir1/dir2/dir3 cd / mget file_pattern* close bye EOF rc=$? if ] ... (7 Replies)
Discussion started by: dhruuv369
7 Replies

9. Shell Programming and Scripting

Detect error and exit

Hi, I am using Jenkins and have integrated JMeter for testing. JMeter is generating a file with results properly using shell script. I have to validate the results and exit the shell with non-zero so my jenkins job gets failed. I tried multiple ways to grep the output file and read the results... (2 Replies)
Discussion started by: sitaram
2 Replies
LVREMOVE(8)						      System Manager's Manual						       LVREMOVE(8)

NAME
lvremove - remove a logical volume SYNOPSIS
lvremove [-A|--autobackup {y|n}] [-d|--debug] [-f|--force] [-h|--help] [-v|--verbose] LogicalVolumePath [LogicalVolumePath...] DESCRIPTION
lvremove allows you to remove one or more inactive logical volumes. OPTIONS -A, --autobackup y/n Controls automatic backup of VG metadata after the change ( see vgcfgbackup(8) ). Default is yes. -d, --debug Enables additional debugging output (if compiled with DEBUG). -f, --force Force remove without confirmation. -h, --help Print a usage message on standard output and exit successfully. -v, --verbose Gives verbose runtime information about lvremove's activities. Example "lvremove -f /dev/vg00/lvol1" removes that inactive logical volume unconditionally. DIAGNOSTICS
lvremove returns an exit code of 0 for success and > 0 for error: 1 no logical volume name on command line 2 invalid logical volume name 3 error checking existence of volume group 4 inactive volume group 5 error getting VGDA from kernel 6 error getting status of logical volume from kernel 7 open logical volume cannot be removed 8 error reading VGDA 9 error removing logical volume from VGDA 10 error removing logical volume from kernel 11 error writing VGDA to physical volume(s) 95 driver/module not in kernel 96 invalid I/O protocol version 97 error locking logical volume manager 98 invalid lvmtab (run vgscan(8)) 99 invalid command line ENVIRONMENT VARIABLES
LVM_AUTOBACKUP If this variable is set to "no" then the automatic backup of VG metadata is turned off. LVM_VG_MAX_BACKUPS This variable determines the backup history depth of kept VGDA copy files in /etc/lvmconf. It can be set to a positive number between 0 and 999. The higher this number is, the more changes you can restore using vgcfgrestore(8). LVM_VG_NAME The default Volume Group Name to use. Setting this variable enables you to enter just the Logical Volume Name rather than its com- plete path. See also lvm(8), lvcreate(8), lvdisplay(8), lvscan(8) AUTHOR
Heinz Mauelshagen <Linux-LVM@Sistina.com> Heinz Mauelshagen LVM TOOLS LVREMOVE(8)
All times are GMT -4. The time now is 03:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy