niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
Passing parameters back from a function
Post new topic   Reply to topic Page 2 of 43 [637 Posts] View previous topic :: View next topic
Goto page:  Previous  1, 2, 3, 4, ..., 41, 42, 43 Next
Author Message
Big and Blue
*nix forums addict


Joined: 21 Feb 2005
Posts: 95

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: How to display the each executed line of a shell script? Reply with quote

Matt Benson wrote:

Quote:
When I start (in ksh) a shell script test.sh
How do I let the shell interpreter display each line he will execute
just before he is really executing it.
The display should include the real content of variables.

Can't see what this has to do with perl, but

set -x


--
Just because I've written it doesn't mean that
either you or I have to believe it.
Back to top
Erkan Yanar
*nix forums beginner


Joined: 27 May 2005
Posts: 6

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: How to display the each executed line of a shell script? Reply with quote

Am Wed, 9 Feb 2005 01:05:20 +0100,schrieb Matt Benson :
Quote:
When I start (in ksh) a shell script test.sh
How do I let the shell interpreter display each line he will execute
just before he is really executing it.
The display should include the real content of variables.


set -x

tschazu
erkan

--
über den grenzen muß die freiheit wohl wolkenlos sein
Back to top
Nunya Bizness
*nix forums beginner


Joined: 22 Feb 2005
Posts: 14

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: How to create a formatted timestamp and use it in filename in a script? Reply with quote

Ulf Meinhardt wrote:
Quote:
I want to
1.) get the current timestamp (including milliseconds !)
2.) format it according to usual options and finally
3.) create a filename from it

All together it should be similar to:

myts=getTimestamp(dd.MM.yyyy_HH:mm:ss:ms)
myfilename=aaa_{$ts}.log

How do I do this in unix shell script ?

Ulf

You can use the date command to grab the current timestamp, but that is

only going to get you to the second, not the millisecond.

I'm sure I have the wrong formatting characters below and I don't have
access to the man page for date right now but try something like this:

myts=`date "+%d.%m.%Y_%h:%m:%s"`

That should get you close. If you need to have milliseconds in the
string, you can always hardcode them to .00
Back to top
Heiner Steven
*nix forums Guru Wannabe


Joined: 19 Feb 2005
Posts: 170

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: How to find all files containing a certaing (text) string? Reply with quote

Chris F.A. Johnson wrote:
Quote:
On Tue, 01 Feb 2005 at 21:38 GMT, Alexander Skwar wrote:

· Bev A. Kupf <bevakupf@myhome.net>:


On Tue, 1 Feb 2005 19:52:04 +0100,
Viet Nguyen (downup@turtle.com) wrote:

I want to find all files matching *.log which contain the string "paul" inside.
Ok, the first part is clear:

find / -name "*.log" -type f -print

but how do I specify the second filter with "paul" ?

If you don't have a recursive grep (like GNU grep -- which was previously
suggested in this thread), you can use:

find / -name "*.log" -type f -print -exec grep -l paul {} \;

The "-print" is superflous.

Not in older versions of find.
[...]


In combination with "-exec" print always was superfluous.

Recent "find" implementations use "-print" as a default action
if no other action was specified, but even old "find" would
call "-exec" if there was no "-print".

Heiner
--
___ _
/ __| |_ _____ _____ _ _ Heiner STEVEN <heiner.steven@nexgo.de>
\__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
Back to top
Heiner Steven
*nix forums Guru Wannabe


Joined: 19 Feb 2005
Posts: 170

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: how to send mail using shell script?? Reply with quote

ambs.tech@gmail.com wrote:
Quote:
Hi all,

I am writing a program in C in which I need to read email addresses
from a file and mail the program to those email addresses. Is this
doable using shell script??? any help would be much appreciated.

file="birthdaygreetings.txt"
subject="Invitation to my birthday party!"

while read address
do
mailx -s "$subject" "$address" < "$file"
done

Heiner
--
___ _
/ __| |_ _____ _____ _ _ Heiner STEVEN <heiner.steven@nexgo.de>
\__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
Back to top
Robert Bonomi
*nix forums Guru Wannabe


Joined: 23 Mar 2005
Posts: 175

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: Wanted: GNU utility (similar to sed) to edit text files directly. Reply with quote

In article <ln1xc0ggun.fsf@nuthaus.mib.org>,
Keith Thompson <kst-u@mib.org> wrote:
Quote:
bonomi@host122.r-bonomi.com (Robert Bonomi) writes:
[...]
Anything that edits 'in place' will have to _rewrite_ the file anyway,
Therefore there is _very_little_ performance penalty to using:

for file in $filelist ; do
sed -f {{commandfile}} $file > /tmp/$$.tmpfile && mv /tmp/$$.tmpfile $file
done

In fact, any _smart_ editor program does *exactly* that; to ensure that there
is always a 'good' copy of the file present -- if 'something bad happens'
_while_ the program is writing back into the _source_ file, then your *ONLY*
copy of the data is trashed. Not good. <grin

If you put the temp file in the same directory as the input file, the
"mv" will just be a rename rather than a copy.

*Almost* correct. As long as source and destinaton are on the same
_filesystem_, 'mv' reduces to a rename.

Quote:
For some applications,
it can be important to avoid having a partial copy of the file while
the copy is in progress; this avoids that. It's also more
fault-tolerant.
Back to top
Jacob Turner
*nix forums beginner


Joined: 19 Feb 2005
Posts: 1

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: How to create a formatted timestamp and use it in filename in a script? Reply with quote

Ulf Meinhardt wrote:
Quote:
I want to
1.) get the current timestamp (including milliseconds !)
2.) format it according to usual options and finally
3.) create a filename from it

All together it should be similar to:

myts=getTimestamp(dd.MM.yyyy_HH:mm:ss:ms)
myfilename=aaa_{$ts}.log

How do I do this in unix shell script ?

Ulf


Well it depends on what shell you are using and what unix you are using.
Start with man date to get the options for the date command and work
from there. Milliseconds may be a problem for the date command on some
nix's though.

Jacob
Back to top
Geoff Clare
*nix forums addict


Joined: 25 Feb 2005
Posts: 64

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: ksh: why use expr? Reply with quote

Stephane CHAZELAS <this.address@is.invalid> wrote, on Wed, 02 Feb 2005:

Quote:
tr is one of the rare command with which you can portably use
'\11' for <Tab

It's not portable to EBCDIC-based systems, where <tab> would be '\5'.

--
Geoff Clare <netnews@gclare.org.uk>
Back to top
Marty
*nix forums Guru


Joined: 16 Mar 2005
Posts: 660

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: [OT] Re: wildcard's in scripts Reply with quote

2005-02-3, 09:28(+00), Chris F.A. Johnson:
[...]
Quote:
Chris, as you appear to be using slrn, please note that you can
hist <Meta-p> or <Esc-p> to retrieve the article to which the
current article is replying.

I know that, and I do use it. But it's annoying, and with
intelligent quoting, unnecessary.

OK, agreed, I just thought that you might have been unaware of
that.

(BTW, HS (hors sujet) is the French equivalent of OT (off
topic), sorry for that).

regards,
Stéphane
Back to top
Marty
*nix forums Guru


Joined: 16 Mar 2005
Posts: 660

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: How to find all files containing a certaing (text) string? Reply with quote

2005-02-03, 01:22(+00), Keith Thompson:
[...]
Quote:
find -print is simply not suited to xargs input. xargs expect a
very specific input format, not a newline separated list.

find / -name "*.log" -type f -print0 | xargs -0 grep -Hn paul

Yes, which are GNU and BSD specific. And you may want to add the
"-r" option to xargs.

But,

find / -name "*.log" -type f -exec grep -n paul /dev/null {} +

may be more efficient and is POSIX.

--
Stéphane
Back to top
Keith Thompson
*nix forums Guru


Joined: 28 Feb 2005
Posts: 5173

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: How to find all files containing a certaing (text) string? Reply with quote

Stephane CHAZELAS <this.address@is.invalid> writes:
Quote:
2005-02-01, 14:04(-05), John-Paul Stewart:
[...]
Pipe the output to grep:

find / -name "*.log" -type f -print | xargs grep -Hn paul

That will not work correctly if the filenames contain blanks or
newlines or single or double quotes or backslashes.

find -print is simply not suited to xargs input. xargs expect a
very specific input format, not a newline separated list.

find / -name "*.log" -type f -print0 | xargs -0 grep -Hn paul

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Back to top
Chris F.A. Johnson
*nix forums Guru


Joined: 20 Feb 2005
Posts: 2268

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: wildcard's in scripts Reply with quote

On Wed, 02 Feb 2005 at 18:23 GMT, new2linux wrote:
Quote:
Chris, which kind of quotes ? do you have an example ? i've actually
tried quotes, both single & double and it didn't work.

Are you talking to me?

Please include relevant parts of the post so that I know what you
are referring to.

Also "it didn't work" tells me nothing about your problem. Post the
command you used and the results, and explain why they are not
what you wanted.


--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
===================================================================
My code (if any) in this post is copyright 2005, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Back to top
new2linuxos
*nix forums beginner


Joined: 10 Mar 2005
Posts: 13

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: wildcard's in scripts Reply with quote

Chris, which kind of quotes ? do you have an example ? i've actually
tried quotes, both single & double and it didn't work.
Back to top
Shekar
*nix forums beginner


Joined: 25 Feb 2005
Posts: 14

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: Bash echo issues Reply with quote

Thanks every one. It looks like printf is working and also the echon()
routine is also great.
Thanks again.

Shekar
Back to top
Keith Thompson
*nix forums Guru


Joined: 28 Feb 2005
Posts: 5173

PostPosted: Sat Feb 19, 2005 8:46 pm    Post subject: Re: Wanted: GNU utility (similar to sed) to edit text files directly. Reply with quote

bonomi@host122.r-bonomi.com (Robert Bonomi) writes:
Quote:
In article <ln1xc0ggun.fsf@nuthaus.mib.org>,
Keith Thompson <kst-u@mib.org> wrote:
bonomi@host122.r-bonomi.com (Robert Bonomi) writes:
[...]
Anything that edits 'in place' will have to _rewrite_ the file anyway,
Therefore there is _very_little_ performance penalty to using:

for file in $filelist ; do
sed -f {{commandfile}} $file > /tmp/$$.tmpfile && mv /tmp/$$.tmpfile $file
done

In fact, any _smart_ editor program does *exactly* that; to ensure
that there is always a 'good' copy of the file present -- if
'something bad happens' _while_ the program is writing back into
the _source_ file, then your *ONLY* copy of the data is trashed.
Not good. <grin

If you put the temp file in the same directory as the input file, the
"mv" will just be a rename rather than a copy.

*Almost* correct. As long as source and destinaton are on the same
_filesystem_, 'mv' reduces to a rename.

Right, and putting them in the same directory is the easiest way to
guarantee that they're on the same filesystem. (I wrote "If", not "If
and only if".)

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 2 of 43 [637 Posts] Goto page:  Previous  1, 2, 3, 4, ..., 41, 42, 43 Next
View previous topic :: View next topic
The time now is Tue Dec 02, 2008 6:08 am | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Function Pointer Sikandar C 3 Fri Jul 21, 2006 1:23 pm
No new posts Shortening URLs passing through a squid hierarchy Irvine, Doug - Resources Squid 0 Fri Jul 21, 2006 10:15 am
No new posts Arbitrary function with parameter darknails@gmail.com C++ 2 Fri Jul 21, 2006 9:58 am
No new posts mod_rewrite to go from http to https and back sevans@bigskypenguin.com Apache 0 Fri Jul 21, 2006 5:12 am
No new posts Is there C/C++ corresponding function in Linux for Java's... xiebopublic@gmail.com apps 4 Fri Jul 21, 2006 3:22 am

Credit Cards | Mortgage Calculator | Loans | Online Gift Shopping | Работа в Канаде
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3076s ][ Queries: 16 (0.1891s) ][ GZIP on - Debug on ]