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:

#!/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

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

thank you for your help sauron :slight_smile:

give this a test ride:


#!/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]