Sponsored Content
Full Discussion: doing own custom parameters
Top Forums Shell Programming and Scripting doing own custom parameters Post 302488449 by m.d.ludwig on Monday 17th of January 2011 07:43:37 AM
Old 01-17-2011
I've run into this issue when I wrote an rsync script, in which I had to eval the command to get things to work properly, as in:
Code:
eval $RSYNC $rsync_param $SRC_DIR $USER@$TRG_SRV:$TRG_DIR >> $LOG_FILE

To demonstrate what is happening, I created a quick script to display the number of parameters, and the parameters themselves:
Code:
#! /bin/sh

echo '#:' ${#}
while [[ 0 -lt ${#} ]]; do echo "${1}"; shift; done | cat -n

And here are the results:
Code:
trogdor $ ./countem a b c d
#: 4
     1    a
     2    b
     3    c
     4    d

trogdor $ ./countem a 'b c' d
#: 3
     1    a
     2    b c
     3    d

Which is as expected. But if we:
Code:
trogdor $ ARGS="a 'b c' d"

trogdor $ ./countem ${ARGS}
#: 4
     1    a
     2    'b
     3    c'
     4    d

${ARGS} is expanded into four tokens. Double-quoting doesn't help either:
Code:
trogdor $ ./countem "${ARGS}"
 #: 1
     1    a 'b c' d

What you need to do is have the shell re-parse your command line, so that it is recognizes the quoting within your variables:
Code:
trogdor $ eval ./countem "${ARGS}"
  #: 3
     1    a
     2    b c
     3    d

Or without the quotes:
Code:
trogdor $ eval ./countem ${ARGS}
#: 3
     1    a
     2    b c
     3    d

Be warned, the script will evaluate the command line twice. Be careful with characters that will cause command line expansion.
This User Gave Thanks to m.d.ludwig For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to custom application name in `ps -ef`?

A program named /usr/bin/aa.sh, two parameters: 11, 22. after start it, the row in `ps -ef` is almost like the following: root 12198 10278 0.0 Nov 25 pts/3 0:00.23 /usr/bin/aa.sh 11 22 but I want to change "/usr/bin/aa.sh 11 22" to one rule string, such as: "AA_11_22", how to... (1 Reply)
Discussion started by: linkjack
1 Replies

2. Solaris

Custom pam module

Does anyone know how to create a custom pam module for modifying the login authentication procedure? (1 Reply)
Discussion started by: mhm4
1 Replies

3. Shell Programming and Scripting

Custom PS command

(0 Replies)
Discussion started by: goldfish
0 Replies

4. UNIX for Dummies Questions & Answers

Changing ip in a custom way

Hi. I hope someone can help me. I have e very special question. I have a Lunix server and I have installed Webmin on it. This way, I can create a login for an other user and give him restricted access to some custom commands I set up. One of the commands i would like to setup, is for him to... (9 Replies)
Discussion started by: Wonderke
9 Replies

5. AIX

tuning network parameters : parameters not persist after reboot

Hello, On Aix 5.2, we changed the parameters tcp_keepinit, tcp_keepintvl and tcp_keepidle with the no command. tunrestore -R is present in inittab in the directory /etc/tunables we can clearly see the inclusion of parameters during reboot, including the file lastboot.log ... (0 Replies)
Discussion started by: dantares
0 Replies

6. Shell Programming and Scripting

custom command

hi I am trying to make my own commands in my linux.I thought a command for changing directories will be easy. I made a simple file amd made the entries #!/bin/bash cd /opt/mydir I then made the file executable and then moved it to /usr/bin. But when i type the script name nothing... (2 Replies)
Discussion started by: born
2 Replies

7. Shell Programming and Scripting

Custom Shell

I have a jump off server, which grants SSH access to a few other servers. I would like to create a custom shell which can be assigned to specific user accounts which runs a menu script upon login, where they can select which server they want to jump too, however should they hit ctrl-c or any... (1 Reply)
Discussion started by: JayC89
1 Replies

8. Red Hat

Custom nagios configuration

Hi, I want to configure nagios core with my own scripts.Default configuration has been done like ping,http,Root partition,..so on... But according to my requirement i have a script called cpumon.sh which will monitor the current cpu usage. I gone through below link but could not find out... (1 Reply)
Discussion started by: mastansaheb
1 Replies

9. Programming

Remote login UNIX box from java passing parameters to the custom script called in the profile

Hello Good Day / Guten Tag.... I have to login the server and the user profile contains some scripts which need the inputs to be taken from the keyboard. So I use the method to conn.authenticateWithKeyboardInteractive(username, new InteractiveCallback() { public String... (1 Reply)
Discussion started by: Sanalkumaran
1 Replies

10. Shell Programming and Scripting

Custom Report

Hi All, Am getting the raw report from the source and need to prepare the custom report as per the requirement. Requirement keep getting change according to the need. Raw data is as below /* ----------------- test_job_hu ----------------- */ insert_job: test_job_hu job_type: CMD... (4 Replies)
Discussion started by: pradeep84in
4 Replies
All times are GMT -4. The time now is 07:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy