Script not working
Ray Parrish
crp at cmc.net
Thu Aug 13 16:00:04 UTC 2009
Hello,
I am having difficulty with a bash script. I want to loop through a file
line by line looking for a certain word or phrase to be on a line. When
I find the match, I want to load the next line into xclip.
Here is my code so far -
#!/bin/sh
saved=" "
while read f
do
echo $f
echo $1
if "${1}" = "${saved}" ; then
xclip -in -selection clipboard $f
else
saved="$f"
fi
#
done < /home/ray/.hidden/file.txt
I am passing the script the command line parameter "U S Bank" which
finds it's way into $1 no problem. The problem is that even when both
echo statements put out the value
U S Bank
for $f and $1 the if statement bombs with the following errors.
Facebook
U S Bank
/home/ray/.hidden/LoadClip.sh: 14: U S Bank: not found
U S Bank
U S Bank
/home/ray/.hidden/LoadClip.sh: 14: U S Bank: not found
What am I doing wrong that makes that if statement insist on failing to
detect that $saved and $1 are equal to each other???
I changed the code to the following -
#!/bin/sh
saved=" "
while read f
do
echo "\$f" $f
echo "\$1" $1
echo "\$saved" $saved
if "$1" = "$saved" ; then
xclip -in -selection clipboard "$f"
else
saved="$f"
fi
#
done < /home/ray/.hidden/file.txt
Now the output is as follows
$f dl;fjew547;pd;lfwpfnls
$1 U S Bank
$saved U S Bank
/home/ray/.hidden/LoadClip.sh: 15: U S Bank: not found
Does anyone know what I'm doing wrong?
Later, Ray Parrish
--
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com
More information about the ubuntu-users
mailing list