04-12-2014
Quote:
Originally Posted by
fpmurphy
Using a case statement:
I like the case-statement for this task. You can also easily add another block to fine tune the error handling, e.g.
??*) echo Too many characters;;.
Regards,
Alister
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
there are many script in my project.i am having a problem when i am trying to quit from child script.what is the command to wrap up all the parent script and calling script as well? exit 0 is not working.please help.... (1 Reply)
Discussion started by: arghya_owen
1 Replies
2. Shell Programming and Scripting
I have a script abc.sh. Its contents are as follows: (7 Replies)
Discussion started by: lassimanji
7 Replies
3. Shell Programming and Scripting
I have a script which has the following statement,
/opt/oracle/product/9i/bin/sqlplus << EOC >> $LOG_FILE 2>&1
username/password ---- Enters the SQL prompt
@/export/home/oracle/shells/grant_userview.sql ---Runs the SQL script
@/export/home/oracle/shells/grant_proc_userview.sql ---Runs the... (6 Replies)
Discussion started by: welldone
6 Replies
4. Shell Programming and Scripting
Hi,
I am trying to exit the script from a function.
I was in assumption that if we use exit ( inside or outside the function) it will exit from the script.
alternatively, return will exit from that particular function.
but in my case, exit is exiting from the function and not the script.... (8 Replies)
Discussion started by: shellwell
8 Replies
5. Shell Programming and Scripting
I have a script planned for the Helpdesk to allow them to (on a couple of RHEL 3 / RHEL 5 servers) reset passwords, stop / start printers, and clear print queues. The appropriate sudo permissions were given to their accounts, and the individual functions all work just fine. The ability to move... (0 Replies)
Discussion started by: tearsong
0 Replies
6. Shell Programming and Scripting
I have to write a script in ksh which again should call another script. Say A.ksh is calling B.ksh. Now in B.ksh if the condition we are checking for is true then we have to go back to the main script A.ksh or if the condition in B.ksh is false then we have to totally come out of the scripts.
I... (1 Reply)
Discussion started by: vpv0002
1 Replies
7. Shell Programming and Scripting
What would cause a script to work under one user account and not another? Here's an example of what I'm referring to.
Here's a simple script. Let's put it in a file called “thescript”.
#! /bin/bash
alias a='echo hello world'
a
Here are the results when this script is executed logged in... (3 Replies)
Discussion started by: sszd
3 Replies
8. Shell Programming and Scripting
Hi Team,
Need your help for the below code snippet. I wrote a module to read the file names remote server using file name convention.
Issue : My script is coming out from while loop without reading complete file.
test1()
{
while read line
do
echo $line
file_nm_convention=`echo... (3 Replies)
Discussion started by: gvkumar25
3 Replies
9. Shell Programming and Scripting
function2()
{
cmd1
cmd2
cmd3
....
cmdn
}
function2()
{
cmd11
cmd12
cmd13
....
....
}
for i in {1,2} (7 Replies)
Discussion started by: yanglei_fage
7 Replies
10. UNIX for Beginners Questions & Answers
HI Team -
I'm running into a weird issue when trying to call a .ksh script.
In my shell script, I'm using the following command to call my environment file:
cd /hypbin/test
./_env.ksh
But it's saying not found. Permissions are set correctly, shebang is set but I'm unsure why it's not... (5 Replies)
Discussion started by: SIMMS7400
5 Replies
LEARN ABOUT CENTOS
shell-quote
SHELL-QUOTE(1) User Contributed Perl Documentation SHELL-QUOTE(1)
NAME
shell-quote - quote arguments for safe use, unmodified in a shell command
SYNOPSIS
shell-quote [switch]... arg...
DESCRIPTION
shell-quote lets you pass arbitrary strings through the shell so that they won't be changed by the shell. This lets you process commands
or files with embedded white space or shell globbing characters safely. Here are a few examples.
EXAMPLES
ssh preserving args
When running a remote command with ssh, ssh doesn't preserve the separate arguments it receives. It just joins them with spaces and
passes them to "$SHELL -c". This doesn't work as intended:
ssh host touch 'hi there' # fails
It creates 2 files, hi and there. Instead, do this:
cmd=`shell-quote touch 'hi there'`
ssh host "$cmd"
This gives you just 1 file, hi there.
process find output
It's not ordinarily possible to process an arbitrary list of files output by find with a shell script. Anything you put in $IFS to
split up the output could legitimately be in a file's name. Here's how you can do it using shell-quote:
eval set -- `find -type f -print0 | xargs -0 shell-quote --`
debug shell scripts
shell-quote is better than echo for debugging shell scripts.
debug() {
[ -z "$debug" ] || shell-quote "debug:" "$@"
}
With echo you can't tell the difference between "debug 'foo bar'" and "debug foo bar", but with shell-quote you can.
save a command for later
shell-quote can be used to build up a shell command to run later. Say you want the user to be able to give you switches for a command
you're going to run. If you don't want the switches to be re-evaluated by the shell (which is usually a good idea, else there are
things the user can't pass through), you can do something like this:
user_switches=
while [ $# != 0 ]
do
case x$1 in
x--pass-through)
[ $# -gt 1 ] || die "need an argument for $1"
user_switches="$user_switches "`shell-quote -- "$2"`
shift;;
# process other switches
esac
shift
done
# later
eval "shell-quote some-command $user_switches my args"
OPTIONS
--debug
Turn debugging on.
--help
Show the usage message and die.
--version
Show the version number and exit.
AVAILABILITY
The code is licensed under the GNU GPL. Check http://www.argon.org/~roderick/ or CPAN for updated versions.
AUTHOR
Roderick Schertler <roderick@argon.org>
perl v5.16.3 2010-06-11 SHELL-QUOTE(1)