Advertisement

Echoing commands in a bash script?

Started by February 19, 2007 07:51 PM
4 comments, last by Sander 17 years, 10 months ago
So is there a way that I can echo commands in bash? Unfortunately a search for 'bash command echo' has a low S:N. An example for clarity:

#!/bin/bash
echo "Hi!"
find ~ -iregex '.*jpe?g' | sort

should produce something like:

me:~$ examplescript
: echo "Hi!"
Hi!
: find /home/me -iregex '.*jpe?g'
: sort
/home/me/pictures/frog.jpeg
/home/me/pictures/giraffe.jpeg
/home/me/webstuff/aardvark.jpg
me:~$ _

I could always explicitly echo the commands I'm interested in, but it seems like there should be a flag I can set in stty or some marker like @command. Any ideas?
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)
Try this:

set -o verbose #echo onset +o verbose #echo off
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
Advertisement
Sweet. All this time and I didn't know set could be used like that... revoke my geek license!

set -v works great, but after digging some more, set -x is precisely what I need.

Thanks!
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)
To present a second way, without switching autoecho on and off:
---------------
use: ``
instead of ""/''

`` means executing the thing between these two (axon de vu? (don't really know how they're called) )
and they work with pipes and all that funstuff.

eg: echo `ls -la | grep .c`

or:

for a in `seq 0 100`
do
...
done

(seq counts from 0 to 100 in this case and prints out this sequence)

--
Ronny
Is there any way to make it so the set +o call isn't echo'd?
Quote: Original post by hydroo
`` means executing the thing between these two (axon de vu? (don't really know how they're called) )
and they work with pipes and all that funstuff.


They're called backticks. The name you're thinking about the accent acute and and accent grave, which are slightly different symbols.

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

This topic is closed to new replies.

Advertisement