passing string which includes metacharacters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passing string which includes metacharacters
# 1  
Old 03-10-2009
passing string which includes metacharacters

I'm trying to create a bash script that takes a URL as one of its arguments like this:
Code:
./script.sh http://url.cfm?asdf&asdf=234
variable=$1
echo $variable

I'm having trouble storing the URL because it contains the meta character "&" which is being interpreted... thus when I run the script I get this:

./script.sh: line 11: [1: command not found
http://url.cfm?asdf
# 2  
Old 03-10-2009
Use quotes to protect it:

./script.sh 'http://url.cfm?asdf&asdf=234'
# 3  
Old 03-11-2009
Would there be any way to do it inside the script without protecting (that way I don't have to ask people running the script to remember to quote it out) ?

Last edited by kds1398; 03-11-2009 at 09:40 PM.. Reason: typo
# 4  
Old 03-11-2009
No. The shell is doing this before the script starts to run. Anyone who uses a shell to enter commands should get used to the need to quote special characters. But an alternative might be to have the script ask for the url and read the response directly.
# 5  
Old 03-11-2009
I think reading user input instead of passing it as an argument is just the ticket. Thanks for your assistance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing Day in string

I need to pass days in past 3, 4, 5 day in strings. Today is Feb 7, so past 3, 4, 5 days are: day1="Feb 2" day2="Feb 3" day3="Feb 4" I have set day1 day2 day3 as the variables. So, what I need is to have the day stings to be past 3, 4, 5 days every day. If it Feb 8, they need to... (11 Replies)
Discussion started by: danielshell
11 Replies

2. Shell Programming and Scripting

Passing string from bash to sqlplus

Hello, I have file (PARFILE) with string on first line: INCLUDE=SCHEMA:"IN\( 'SCHEMA1','SCHEMA2','SCHEMA3' \)"In .sh script I use: .... IMPORT_SCHEMA=`awk 'NR==1{print $2}' ${PARFILE}` ...print $2 is because 'SCHEMA1','SCHEMA2','SCHEMA3' is 2nd column in file echo "$IMPORT_SCHEMA"... (5 Replies)
Discussion started by: DjukaZg
5 Replies

3. Shell Programming and Scripting

Passing string as variable(s) in bash

I'm trying to write a basic bash script that takes input you give (what directory, if any, what name, if any ....) and passes the information to find. I'm trying to just create a string with all variables and then pass it to find. So far I have this extremely simple: #!/bin/bash -f ... (2 Replies)
Discussion started by: Starting_Leaf
2 Replies

4. Homework & Coursework Questions

passing letters from an array into a string for string comparison

attempting the hangman program. This was an optional assignment from the professor. I have completed the logical coding, debugging now. ##I have an array $wordString that initializes to a string of dashes ##reflecting the number of letters in $theWord ##every time the user enters a (valid)... (5 Replies)
Discussion started by: lotsofideas
5 Replies

5. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

6. Shell Programming and Scripting

grep regex, match exact string which includes "/" anywhere on line.

I have a file that contains the 2 following lines (from /proc/mounts) /dev/sdc1 /mnt/backup2 xfs rw,relatime,attr2,noquota 0 0 /dev/sdb1 /mnt/backup xfs rw,relatime,attr2,noquota 0 0 I need to match the string in the second column exactly so that only one result is returned, e.g. > grep... (2 Replies)
Discussion started by: jelloir
2 Replies

7. Shell Programming and Scripting

how to search for string that includes folder separator ?

I want to select only second line. I want to search for any line that has both -> input.txt /userA/aaaaaaabbb/jakarta /userA/aaaaaaa/jakarta /userB/aaaaaaabbb/jakarta /userB/aaaaaaa/jakarta This command does have effect of --> $>cat input.txt | /usr/xpg4/bin/grep -E... (13 Replies)
Discussion started by: kchinnam
13 Replies

8. Shell Programming and Scripting

Help needed passing string to command

hi to all code: </div> command... "command_name arg1 arg2 option=xxxxx" example --- useradd username group=xxxxxx. </div> when someone ran this command it point to some other script (say script1), mean post execution of command. in the script1 i need only "xxxxx" value. then i... (5 Replies)
Discussion started by: honeym210
5 Replies

9. Shell Programming and Scripting

Passing string variables

HI all, Very new to shell programming and just wanted some help on how to solve the following problem. I have a small shell script which searches a given file and extracts some string parameters. I want to now be able to call this script from another shell script and somehow pass the parameters... (11 Replies)
Discussion started by: pxy2d1
11 Replies

10. Shell Programming and Scripting

Passing string from function with '*'

Hi I have a shell function which returns string(ksh). The string is an sql statement. This statement can have '*' in its content (i.e. select 100 / 2 *100 from dual). When this happens ret_str will have contents of current directry I run the script from build in sql. Is there any way to fix it... (2 Replies)
Discussion started by: zam
2 Replies
Login or Register to Ask a Question