On how to select the right tool for a given task

Tags
select, shell scripts, tool

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 10-16-2008
On how to select the right tool for a given task

edit by bakunin: I have split the thread to reflect the two different themes it had. Read the original thread here. All the other posts there dealing with the new theme have been moved here, the ones which addressed both i have copied and edited. Enjoy the discussion.

BTW, you don't want to use sed to work on a string.

Use sed for working on files and shell parameter expansion for manipulating strings.

Last edited by bakunin; 10-18-2008 at 06:47 AM..
# 2  
Old 10-16-2008
Quote:
Originally Posted by cfajohnson

BTW, you don't want to use sed to work on a string.

Use sed for working on files and shell parameter expansion for manipulating strings.
[/INDENT]
its perfectly all right to use sed on strings(as well as files of course).
# 3  
Old 10-16-2008
Quote:
Originally Posted by ghostdog74
its perfectly all right to use sed on strings(as well as files of course).

It is wasteful (in terms of both time and resources) to use an external program to do something that the shell can do internally.
# 4  
Old 10-16-2008
Quote:
Originally Posted by cfajohnson

It is wasteful (in terms of both time and resources) to use an external program to do something that the shell can do internally.
i understand where you are coming from. but there are few situations i can think of that using shell provided internals are not suitable
1) writing portable scripts. The syntax that you use for string manipulations in bash for example, is not universal for every shell
2) doing more complex string manipulation like grouped pattern matches.
3) and of course, using sed to go over files can be faster than using pure shell constructs.
# 5  
Old 10-17-2008
Quote:
Originally Posted by ghostdog74
i understand where you are coming from. but there are few situations i can think of that using shell provided internals are not suitable
1) writing portable scripts. The syntax that you use for string manipulations in bash for example, is not universal for every shell

The techniques I used are part of the standard UNIX shell.

They are portable to all modern *nix systems (and many older ones).

I used nothing that is bash specific.
Quote:
2) doing more complex string manipulation like grouped pattern matches.

When a regular expression, rather than wildcard expansion is necessary, then sed might be appropriate (though I would usually prefer awk).
Quote:
3) and of course, using sed to go over files can be faster than using pure shell constructs.

As I said, sed is for working with files.
# 6  
Old 10-17-2008
Quote:
Originally Posted by cfajohnson
They are portable to all modern *nix systems (and many older ones).
older ones like bourne (Solaris) will break. I have not tried csh, but i think it will break too.

Quote:
though I would usually prefer awk).
i prefer awk too.

Quote:
As I said, sed is for working with files.
and strings...
# 7  
Old 10-17-2008
Quote:
Originally Posted by ghostdog74
older ones like bourne (Solaris) will break.

On Solaris, /bin/sh is not a POSIX shell, but there is always one installed. It may be /usr/pkg4/bin/sh, and there is usually ksh and possibly bash.
Quote:
I have not tried csh, but i think it will break too.

csh is not the standard Unix shell, and it will not run standard shell scripts, even old-style Bourne scripts; it is a different language and not recommended for scripting.
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Task 1 bible Atreus20 UNIX for Beginners Questions & Answers 1 3 Days Ago 06:32 PM
[HELP] Easy task justynykas Homework & Coursework Questions 1 04-14-2014 03:08 PM
Can Anyone help me..to do my task in simple way.. nex_asp Shell Programming and Scripting 7 01-21-2013 06:00 AM
need help with an easy task Telis Shell Programming and Scripting 2 03-08-2012 08:05 PM
Task hernand Shell Programming and Scripting 29 06-08-2011 07:08 PM
task hernand Shell Programming and Scripting 10 05-27-2011 08:42 AM
last task for my script dvah Shell Programming and Scripting 4 03-23-2011 02:17 PM
Reboot and Select Proper Boot device or insert Boot media in select Boot device and press a key rpf Boot Loaders 0 03-22-2011 04:20 PM
Need a help to automate a task Renjesh Shell Programming and Scripting 4 12-08-2010 09:14 AM
Help with task daemon james2432 Programming 5 04-09-2009 10:40 PM
Parse an XML task list to create each task.xml file MissI Shell Programming and Scripting 3 11-11-2008 02:20 PM
Need help with a manual task jcalisi Shell Programming and Scripting 4 10-24-2008 05:26 PM
comment and Uncomment single task out of multiple task madhusmita Shell Programming and Scripting 9 06-18-2008 10:42 AM
process vs task hana UNIX for Dummies Questions & Answers 2 07-02-2006 07:32 PM
All times are GMT -4. The time now is 01:29 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.