0

I How can I get the output from grep into a variable? In the following program I've tried the SSID line two ways but I am not getting what I want.

SSID=$(grep) ${FILE} -o empty-ssid
Gives me this

garrett@bedroom ~/Desktop/folder/project $ ./testScript.sh ../OLD-172.28.50.30-system.cfg 
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
./testScript.sh: line 5: ../OLD-172.28.50.30-system.cfg: Permission denied
../OLD-172.28.50.30-system.cfg

SSID=$(grep ${FILE} -o empty-ssid)
Gives me this

garrett@bedroom ~/Desktop/folder/project $ ./testScript.sh ../OLD-172.28.50.30-system.cfg 
grep: empty-ssid: No such file or directory
../OLD-172.28.50.30-system.cfg

Program

FILE=${1}
SSID=$(grep) ${FILE} -o empty-ssid

echo ${FILE}
echo ${SSID}
#END#
2
Contributors
4
Replies
23
Views
4 Years
Discussion Span
Last Post by lewashby
0

This is where you use the back-quote method, as in

SSID=`grep ${FILE} -o empty-ssid`

You do need the file "empty-ssid" to exist in the local directory however or you will still get the "No such file or directory" error.

0

empty-ssid is not a file, it's a line of text inside a file. I thought using the backtick was teh same as using $() ?

0

Not necessarily. In any case, your use of it is incorrect. Ok. You are looking for empty-ssid inside the named file then? If so, your syntax for grep (order of options) is incorrect, and it should be like this:

SSID=`grep -o empty-ssid ${FILE}`

Edited by rubberman

0

garrett@bedroom ~/Desktop/folder/project $ ./testScript.sh OLD-172.28.50.30-system.cfg

Above is what I'm getting now. It's returning $FILE but not $SSID.

Here's what the line looks like now ->

SSID=$(grep -o empty-ssid ${FILE})

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.