![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Add single quotes in string | mrjunsy | UNIX for Dummies Questions & Answers | 1 | 07-18-2008 07:09 AM |
| Awk:Find length of string omitting quotes | jayakumarrt | Shell Programming and Scripting | 2 | 05-09-2008 12:48 AM |
| simple question on string concat | the_learner | High Level Programming | 2 | 08-23-2007 08:09 PM |
| problem with single quotes in a string and findbug | bob122480 | Shell Programming and Scripting | 9 | 01-19-2007 07:38 AM |
| concat string | mpang_ | Shell Programming and Scripting | 1 | 07-25-2006 03:03 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
String concat that keeps quotes
Hi All,
I hope you can help. i am concatenating String variables using the following method. Code:
command="$command$x" Code:
#example script
args=$*
count=0
for x in $args
do
count=`expr $count + 1`
if [ "$count" -gt "3" ]
then
command="$command$x"
fi
done
echo $command
Code:
example this is a test to see if it works test to see if it works Now i am finally coming to my question if i write Code:
example this is a test to "see if" it works test to see if it works it always seems to remove the quotes from the string. how can i keep the quotation in the output Many thanks for your help |
| Forum Sponsor | ||
|
|
|
|||
|
The quotation marks are not passed in literally. Compare:
Code:
vnix$ echo foo foo vnix$ echo "foo" foo vnix$ echo '"foo"' "foo" See further http://www.grymoire.com/Unix/Quote.html As an aside, note that "$@" should be preferred over $* |
|
|||
|
Hi era,
I have noticed that echo $@ or echo $* seem to remove the quotes from the arguments in the scripts. Is there a away to keep this i.e example script example this is an "example" test echo $* or $@ echo's this is an "example" test rather than this is an example test |
|
|||
|
Read the grymoire.com quoting tutorial from the link above. Quote characters are inherently special; you can't get literal quotes through in the shell without additional quoting or other escaping mechanisms.
|
|
|||
|
thanks era, i have been through the link you provide UNIX Shell Quote
this make perfect sense, unfortunately I am in big trouble i am using an application which allows me access to the arguments i cant make changes to the original commands that are passed, so i cant wrap them round / or ' i can just use these arguments to create scripts which i use. The problems is some of the commands that can be passed have quotations which seem to be disappear so i assume there is no walk around this? Many thanks |
| Thread Tools | |
| Display Modes | |
|
|