LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-05-2012, 12:03 PM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Rep: Reputation: 16
Linux .... bash-v what is it?


I have been apending the pipe bash -v to the end of my scripts. It seems to pipe whatever is printed out by the command into an executable something.
I am not sure how it works or what it is - looked on the interwebs adn man pages and could not find a thing.

It is a great tool

Code:
casper@casperbox:~$ ps auxwww   | grep chrome | awk '{print "kill -9 "$2}'| bash -v
kill -9 1235
bash: line 1: kill: (1235) - No such process
kill -9 10633
kill -9 13854
kill -9 20354
kill -9 20358
kill -9 20360
kill -9 20362
kill -9 20886
kill -9 23051
kill -9 23144
kill -9 23302
kill -9 28158
kill -9 29787
kill -9 29878
kill -9 30145
kill -9 31524
 
Old 01-05-2012, 12:11 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Hello,

The -v just means verbose; Using "bash -v," it will print each command to STDOUT before executing the command(s). For a reference/manual, see here - http://tldp.org/LDP/abs/html/options.html

Cheers,

Josh
 
1 members found this post helpful.
Old 01-05-2012, 07:08 PM   #3
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Original Poster
Rep: Reputation: 16
thank you for the refreence - piping commands into a bash -v is a kick a$$ feature.
 
Old 01-05-2012, 07:22 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Actually, that will invoke a new instance/shell of bash.
If you want to see what's going on in a current script, use
Code:
set -v

#OR
#more detail
set -xv
inside your script
 
Old 01-05-2012, 07:56 PM   #5
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Quote:
Originally Posted by chrism01 View Post
Actually, that will invoke a new instance/shell of bash.
If you want to see what's going on in a current script, use
Code:
set -v

#OR
#more detail
set -xv
inside your script
Hmmm.... So I'm wrong? I thought it was strictly for verbose mode.
 
Old 01-05-2012, 08:08 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Yeah, '-v' =verbose, but 'bash' is still a cmd that invokes a new (sub-)shell.
Because its at the end of a pipe (in this instance) you don't notice it
 
Old 01-05-2012, 08:17 PM   #7
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Oh I did! I was just confused on your context and wording of how you said that. All is good!

Cheers,

Josh
 
Old 01-06-2012, 12:04 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Ah, ok sorry about the confusion. I was trying to say to the OP that you can use that switch inside a script, rather than invoking a new sub-shell
 
Old 01-06-2012, 01:17 AM   #9
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Oh ok, I understand now.
 
Old 01-07-2012, 06:05 PM   #10
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Original Poster
Rep: Reputation: 16
what would i use if i did not want the executed commands to out put to the console -
 
Old 01-07-2012, 06:22 PM   #11
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Just take away the -v out of the snippet of code. Alternatively, you could run the following:
Code:
code 1>/dev/null 2>/dev/null
Cheers,

Josh
 
Old 01-07-2012, 08:43 PM   #12
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
To disable an option with set change the minus to a plus.

Code:
set -v	#enable verbosity
set +v	#disable verbosity
This, along with the -x option, is particularly useful in scripts for debugging.

Note that most of the set options correspond to options you can use when invoking bash directly. "bash -v" runs an instance of bash with verbosity enabled (you can add it to the shebang at the top of a script, for example). Or you can run bash with no options first, then use set -v separately to do the same thing.

And as always, the details are in the man page. Start with the OPTIONS section at the top, then scroll down to the SHELL BUILTIN COMMANDS and read the entry for set.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash problem : -bash: [: /bin/bash: unary operator expected J.A.X Linux - Software 1 09-22-2011 06:52 AM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 07:42 PM


All times are GMT -5. The time now is 12:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration