Maintaining Command Line Integrity


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Maintaining Command Line Integrity
# 1  
Old 10-31-2011
Maintaining Command Line Integrity

Hi everyone,

I have a script that takes command line entries, for example
# script.sh 1 "2" 3 4 "5"

I want to be able to maintain the integrity of this command line such that it is processed with the double quotes i.e.:
Code:
 
VAR1=1
VAR2="2"
VAR3=3
VAR4=4
VAR5="5"

The double-quotes are required to keep the command line strings intact.

Any thoughts on how this can be done would be most welcome.

TIA


proc
Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.
# 2  
Old 10-31-2011
Hmm, the only way I can think of is for you to escape the double-quotes when you pass them to your script.

Code:
# /tmp/123.sh 1 \"2\" 3

1
"2"
3

# 3  
Old 11-02-2011
Hi.

Enclose entire string of arguments in single quotes:
Code:
# script.sh '1 "2" 3 4 "5"'

then crack them individually:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate one solution to get quotes into positional parameters.

echo '$*' is :"$*":
echo '$@' is :"$@":
echo '$2 is ' :$2:

set -- $@
echo '$2 is ' :$2:

exit 0

producing:
Code:
% ./s1 '1 "2" 3 4 "5"'
$* is :1 "2" 3 4 "5":
$@ is :1 "2" 3 4 "5":
$2 is  ::
$2 is  :"2":

Very non-standard.

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking integrity copied from remote server using UNIX command

I am getting a file (abc.txt) using scp from remote server. scp <connect string> -i $HOME/.ssh/id_dsa rem_id@hostname:/var/prod/abc.txt /var/prod/abc.out Before loading I need to check if the file is indeed same , for that I thought of checking the line count but when I used ssh command it was... (3 Replies)
Discussion started by: lalitpct
3 Replies

2. Solaris

Maintaining SA logs /var/adm/sa/

Hi all, I have enable sar and the sa cron jobs in the sys account. I would like to however, keep only 1 month of data. Can i check for Solaris10, does sa2 do automatic purging of logs in /var/adm/sa/ that are 1 week old ? -- Answer = yes ( in "/usr/lib/sa/sa2" if you open the script,... (2 Replies)
Discussion started by: javanoob
2 Replies

3. Shell Programming and Scripting

Maintaining file structure

Hi guys, I am trying to store some output in a file and then compare it to another file. I am gathering information from 2 commands: cat /opt/jbin/server.log.tmp > A grep "ephemeral" /opt/jbin/log/server.log.2015-05-02-18 > B The contents of both file are the same. This means if I do a... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

4. Shell Programming and Scripting

Maintaining file currency

I have a common data folder with files like x* which is accessed by 3 unix servers. Now each server will try to pick one file form this folder and move it to its local folder. How to maintain file concurrency in this case?I dont want the same file to be accessed by more than one process. (2 Replies)
Discussion started by: prasperl
2 Replies

5. UNIX for Dummies Questions & Answers

Maintaining HOURLY backups

I have a system where i take hourly back-ups of the system.The script for maintaining full backup for the last 5 days is find /backup/server -type f -mtime +4 -exec rm -f {} \; works fine for keeping the files of some 5 days old. In the case of hourly backups.How do we write to keep... (2 Replies)
Discussion started by: ravi55055
2 Replies

6. UNIX for Advanced & Expert Users

Maintaining different version Control account

How can I maintain different version control account(any common unix based version control like CVS,RCS,SCCS..) from a single UNIX Login Account. Many programmers share a common UNIX user/login account.How do they maintain separate Version Control Account. (1 Reply)
Discussion started by: johnbach
1 Replies

7. UNIX for Dummies Questions & Answers

Command for maintaining the list of commands used

Hi, There is a command by which you can maintain a list of commands previously typed. By this you dont have to type in the same command again and can use the up-down arrows to scroll through the list. Which is this command, i am not able to recall. (8 Replies)
Discussion started by: appledrive
8 Replies

8. UNIX for Advanced & Expert Users

Printing to Windows and maintaining control

I'm new at the entire spectrum of printing in Unix, and especially when--as I understand it--the printers are on a Windows server. At work we have a variety of printers and printing from Windows, or from Unix via lp or lpr works fine. The initial problem: Our users will be printing up to 20... (1 Reply)
Discussion started by: effigy
1 Replies
Login or Register to Ask a Question