LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 08-22-2007, 06:10 AM   #1
indiancosmonaut
Member
 
Registered: Feb 2007
Posts: 65

Rep: Reputation: 15
line of code


I found this piece of code...
kindly help me in what the code does...?

Code:
echo "Usage: ${0##*/}"
Code:
$ ksh script.sh /home/user/somefile.txt
Usage: somefile.txt
Kindly advice,

indiancosmonaut
 
Old 08-22-2007, 06:40 AM   #2
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
I don't use ksh, but with bash at least ${variable##pattern} means:
- Display $variable where the longest match of pattern at the start of the initial value is removed.

Likewise, ${variable#pattern}, ${variable%%pattern} and ${variable%pattern} respectively mean:
- Display $variable where the shortest match of pattern at the start of the initial value is removed.
- Display $variable where the longest match of pattern at the end of the initial value is removed.
- Display $variable where the shortest match of pattern at the end of the initial value is removed.

There are other such usefull notations. See the man page.

Yves.
 
Old 08-22-2007, 03:08 PM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by theYinYeti View Post
I don't use ksh, but with bash at least ...
Same with ksh.
Actually this syntax was created in the Korn shell and later included in POSIX compliant shells including bash.
 
Old 08-24-2007, 01:18 AM   #4
indiancosmonaut
Member
 
Registered: Feb 2007
Posts: 65

Original Poster
Rep: Reputation: 15
Hi theYinYeti & jlliagre,

Thanks to both for the information.
Could you tell me which man page to refer.
Is it the ksh man page? I see it but there is no information regarding the constructs.

Kind regards,

indiancosmonaut
 
Old 08-24-2007, 01:51 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
From the ksh manual page:

Code:
${parameter##word}       Remove Largest Prefix Pattern. The  word
                         is  expanded  to  produce a pattern. The
                         parameter  expansion  then  results   in
                         parameter,  with  the largest portion of
                         the  prefix  matched  by   the   pattern
                         deleted.
 
Old 08-29-2007, 04:25 AM   #6
indiancosmonaut
Member
 
Registered: Feb 2007
Posts: 65

Original Poster
Rep: Reputation: 15
Thanks jlliagre,

I was referring to some abridged doc.
Found the complete ksh man page!

I was referring and i found the following points.

1. ; causes sequential execution of the previous pipeline.
2. & causes asynchronous execution of the previous pipeline.
3. |& causes asynchronous execution of the previous pipeline with a two-way pipe established to the parent shell.

Could you help me out with some example for point 3.

Also,
What is the difference between

Code:
Command /dev/null 2>&1
and

Code:
Command 2>&1 /dev/null
Thanks in advance,

Kind regards,

indiancosmonaut

Last edited by indiancosmonaut; 08-29-2007 at 04:32 AM.
 
  


Reply



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
'line numbers' option in [code] tags nadroj LQ Suggestions & Feedback 6 04-15-2007 05:39 PM
Executing command line through Code socialjazz Programming 2 10-02-2006 03:09 PM
printing line numbers for code bauer172uw Programming 3 04-13-2006 11:10 PM
posting code from command line frankie_DJ Linux - Newbie 3 08-09-2005 08:51 AM
How to compare these two strings in one line code? powerplane Programming 4 07-10-2003 12:09 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 04:32 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
Open Source Consulting | Domain Registration