![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Double quotes or single quotes when using ssh? | password636 | Shell Programming and Scripting | 3 | 05-29-2008 08:52 PM |
| escaping double-quotes inside the script? | GKnight | Shell Programming and Scripting | 3 | 05-05-2008 05:35 PM |
| Bash Shell - # of arguments | DNAx86 | Shell Programming and Scripting | 1 | 01-10-2008 01:23 PM |
| Bash: Reading 2 arguments from a command line | Vozx | Shell Programming and Scripting | 0 | 12-08-2005 05:23 PM |
| retain Line numbers.. in Vi .. OR .. A SHELL SCRIPT | sdlayeeq | Shell Programming and Scripting | 2 | 04-26-2005 04:20 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Retain quotes from bash script arguments
Hi there,
I've been scouring these forums and have found similar threads, but none apparently helped me solved my problem ![]() I'd like to run a command within a bash script, but that command is provided by the user to the script and may contain quotes, which is where the problem lies. My script is (fundamentally): ----- #!/usr/bin/bash commandToRun="$@" $commandToRun ~/t.txt ----- And I'd like to run it using the following: > myscript.sh grep "foo bar" But the quotes are removed by the time I try to run that command from within the script, i.e. the $commandToRun $filename line and so it tries to run > grep foo bar instead of > grep "foo bar" ~/t.txt Thanks for any help, it would be much appreciated! ![]() Danny |
|
||||
|
Hmm, I also tried changing the line that runs the command in the script to:
"$commandToRun" ~/t.txt (which is arguably something I should've done before anyway), but now I get the following: > myscript.sh grep "foo bar" gives grep foo bar: command not found > myscript.sh grep \"foo bar\" gives grep "foo bar": command not found Thanks again though :S Last edited by cypression; 07-18-2008 at 05:50 AM.. Reason: typo |
|
||||
|
Aha!
I don't why I didn't spot this thread before when I was searching, but one of the threads in the 'More UNIX and Linux Forum Topics You Might Find Helpful' section (escaping double-quotes inside the script?) helped me solve it using a simple eval So in the script, I now have: ---- #!/usr/bin/bash commandToRun="$@" eval "$commandToRun" ~/t.txt ---- I still have to run the command with the quotes escaped as zaxxon suggested, but at least it works now ![]() > myscript.sh grep \"foo bar\" |
![]() |
| Bookmarks |
| Tags |
| bash, bash eval, eval, linux |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|