how to use in bash variables and quotes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to use in bash variables and quotes
# 1  
Old 04-11-2009
how to use in bash variables and quotes

I have some troubles with variables and quotes...

I want:

if $URL is empty (no user input) go to http://www.localhost/index.php/ else add this string (search) "?s=+$URL"

EXAMPLE:
No user input
string= http://www.localhost/index.php/

User input = "unix"
string= http://www.localhost/index.php/s=+unix

No luck with:


Code:
#!/bin/bash

read URL
#if [ $? = 1 ];
#then exit
#fi
LINK=$("http://www.localhost/index.php/")
SEARCH=$("?s=+$URL")
if [ $var == "" ]
then
LINK1=$(lynx -dump $LINK)
else
LINK1=$(lynx -dump $LINK$SEARCH)
fi
# exec command:
exec $LINK1


Output:


line 8: ?s=+unix: command not found
line 9: [: ==: unary operator expected
line 16: Lynx: command not found

Last edited by aspire; 04-11-2009 at 01:58 PM..
# 2  
Old 04-11-2009
Hi,
Output:


line 8: ?s=+unix: command not found
you must use echo to dusplay $URL >> SEARCH=$(echo "?s=+$URL")
line 9: [: ==: unary operator expected
what is $var? reading your script $var in null, anyway you must write like this >> if [ "$var" == "" ]
line 16: Lynx: command not found
have you got lynx installed?


Bye
# 3  
Old 04-14-2009
thank you for your help sauron Smilie
# 4  
Old 04-14-2009
give this a test ride:

Code:
#!/bin/bash

echo enter something
read URL

LINK=http://www.localhost/index.php
SEARCH=$LINK${URL:+?s=+$URL}

echo $SEARCH

lynx -dump $SEARCH

You don't want to be doing this:

LINK1=$( lynx.... )

exec $LINK1

this syntax: $( command ) already executes the command.
you'll be exec-ing total garbage.

notice that i've removed that syntax from this code.



[/code]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Complex: bash, using ANSI-C quotes in skript

Hello, I hope someone can hep with this. I use a skript to send multiline Data to a Monitoring system. Bu I'm not able to use linebreaks or escape sequences. The skript is simple like that: #!/bin/bash var="Erste Zeile \n zweite Zeile \n Dritter Teil" zabbix_sender -c... (17 Replies)
Discussion started by: mpmichael
17 Replies

2. UNIX for Beginners Questions & Answers

Bash not recognizing single quotes in Mac?

Hi, I just bought a new mac and have been running a program out of terminal, but even early on I noticed that my single quotes looked a lot different from the ones used in all of the namelists and other files of the program. Specifically, mine are kind of slanted whereas the others are very... (7 Replies)
Discussion started by: jtcastro99
7 Replies

3. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

4. Shell Programming and Scripting

Complex bash/sed, variables and nested quotes

Ok, this one isn't for everybody, it's pretty tough and I've spent a good deal of time on it without figuring it out yet. Can anybody get this script to work: #!/bin/bash cq_fname="%let outputfile="/user/cq_"$1".csv";" sed "29s/.*/\"$cq_fname\"/" file1.sas >... (3 Replies)
Discussion started by: nocloud
3 Replies

5. Shell Programming and Scripting

How to count number of double quotes in bash

Need a little help. I have just a simple string with a lot double quotes in it. I need to be able to parse through this string, and know how many double quotes I have, and where I am, so I can key off every 9th double quote. For example (coding is not complete): #!/bin/bash count=0... (3 Replies)
Discussion started by: Akilleez
3 Replies

6. UNIX for Dummies Questions & Answers

Is there a way to set ' and " as a non quotes type in bash?

Howdy, I got a script that adds a esc char before all chars interpeted by bash shell but I wan't other solution. Is there a way to set ' and " as a non quotes type in bash (some local variable)? Have found that scsh is a non-quoting type shell but after reading Why I don't use scsh as a scripting... (3 Replies)
Discussion started by: johny_be_good
3 Replies

7. Shell Programming and Scripting

quotes in shell variables

On my Debian system under bash the following command returns 24 files. find /root/bin/ -name '*' while the following returns none FIND="-name '*'"; find /root/bin/ $FIND Asking on the Debian Users list I've been shown work arounds but not explanations. I'm hoping someone here can explain 'why'... (3 Replies)
Discussion started by: mmcclain
3 Replies

8. Shell Programming and Scripting

Use variables with double quotes sed -i

I have the following line of code: sed -i "/MatchText/ s/${tgrepLine}/${tNewLine}/" filename.outputfilename.output contains this: blablabla PATH=".:/home/root/bin/:/usr/local/bin/" blablablaVariable ${tgrepLine} contains: PATH=".:/home/root/bin/:/usr/local/bin/" Variable ${tNewLine}... (3 Replies)
Discussion started by: inspire87
3 Replies

9. Shell Programming and Scripting

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 :rolleyes: 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.... (9 Replies)
Discussion started by: cypression
9 Replies

10. AIX

how to pass variables surrounded in double quotes to awk?

Hi, I'm making progress on this but hung up on one last detail. I'd like to use AWK to pass the system date and time(among other things) to the first line of a file. Here's what I have: BEGIN {TOTALPP = 0;FREEPP=0;USEDPP=0;print "LPAR NAME:",lpar,"DATE:",tdate } I call AWK with the... (4 Replies)
Discussion started by: cruiser
4 Replies
Login or Register to Ask a Question