script not working

New to Debian (Or Linux in general)? Ask your questions here!

script not working

Postby Agvaniot » 2017-08-06 13:33

i am trying to extract the second field from a file and send it to clipit

Code: Select all
#!/bin/bash

file=$1
expression=$2

if [ -z "$file" ]  || [ -z "$expression" ]; then
echo "file or expression is missing"
exit 1
fi

grep "$expression" "$file" | cut -d: -f2 | clipit

Agvaniot
 
Posts: 37
Joined: 2017-07-26 13:07

Re: script not working

Postby Agvaniot » 2017-08-06 14:29

EDITED IMPROVED VERESION
Code: Select all
#!/bin/bash

file=$2
expression=$1

if [ -z "$file" ]  || [ -z "$expression" ]; then
echo "file or expression is missing"
exit 1
fi

grep "$expression" "$file" | cut -d: -f2 | clipit
Agvaniot
 
Posts: 37
Joined: 2017-07-26 13:07

Re: script not working

Postby kopper » 2017-08-07 09:08

Agvaniot wrote:i am trying to extract the second field from a file and send it to clipit

That's neat. And what is the problem? Are we supposed to run this and debug it for you? If you want help, be more specific.

Since I can only guess, here's a shot in the dark.. 1) You don't need quotation marks to use the variables after grep. 2) In what order are you trying to give the arguments? You declare file as first variable, and expression second. However you have it other way around in your actual command. Ensure that you're passing the arguments in right order when you execute your script.

I think the reason for lack of replies in this thread is that everybody have better use for their time than playing "Guess who" with you.
Debian 9 with i3
Secure your stuff: Securing Debian Manual
Don't break your stuff: Source List Management DontBreakDebian
kopper
 
Posts: 49
Joined: 2016-09-30 14:30

Re: script not working

Postby debiman » 2017-08-08 06:08

i tend to agree with the previous poster, but i use clipit and it was easy for me to test:
Code: Select all
echo bla | clipit
clipit bla

this feature does NOT work although advertised in the man page:
Code: Select all
   CLI EXAMPLES
       Put text in the clipboard
               echo "copied to clipboard" | clipit
               clipit "copied to clipboard"

       Put text in the clipboard and print the clipboard contents
               echo "copied to clipboard" | clipit -c
there are, however, other applications that can put text in the clipboard.
xclip.
User avatar
debiman
 
Posts: 1086
Joined: 2013-03-12 07:18


Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable