Script not working

Ray Parrish crp at cmc.net
Thu Aug 13 17:29:48 UTC 2009


Smoot Carl-Mitchell wrote:
> On Thu, 2009-08-13 at 09:00 -0700, Ray Parrish wrote:
>   
>> 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
>>
>>     
>
> xclip is expecting to read from the *file* $f in the script and cannot
> find the file.  You want to change
>
> xclip -in -selection clipboard $f
>
> to
>
> echo $f | xclip -in -selection clipboard
>   
I canged the code to the following before it would work properly. -

saved=" "
while read f
do
    if  [ "$1" = "$saved" ] ; then
        echo "${f}" | xclip -selection clipboard
        exit  
    fi
    saved="$f"
#
done < /home/ray/.hidden/file.txt

Note the [] pair around the if condition... It was necessary to add 
those, to get this to work as well as piping $f through echo into xclip.

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