use of hyphen in #! line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting use of hyphen in #! line
# 1  
Old 03-28-2007
use of hyphen in #! line

In one script i have seen - in #! line can somebody explain the meaning of -(hyphen) here

Code:
#! /bin/sh -

# 2  
Old 03-28-2007
I don't think it serves any useful purpose.
# 3  
Old 03-28-2007
At first view and some experimenting i think you are right but i would request somebody who knows the answer pls explain.
# 4  
Old 03-28-2007
ok, my explanation...

well, looking through man sh there is no hyphen command line.
as we all know Smilie if $0 begins with a '-' then it is a login script,
but this is not the case. Often a lone - (e.g cat - )
means take stdin, well a #! line takes stdin as the file anyway
so I think myself it's a redundant use of this meaning.


p.s. I have no work today
# 5  
Old 03-28-2007
Code:
echo 'ls' | sh -

does exactly what you expect, sh reads from stdin. I think it's an artifact from very antique systems. Chris F A Johnson posts here and will know definitely.
# 6  
Old 03-28-2007
See this page and scroll down to the RATIONALE section near the end.
# 7  
Old 03-29-2007
Thank you all for the interest.What i found is this is something related with the security and prevent some kind of spoofing attacks(mainly with sid).
The text posted below is from the link posted by Perderabo.
Quote:
sh -
or by:
#! usr/bin/sh -
the historical systems have assumed that no option letters follow. Thus, this volume of IEEE Std 1003.1-2001 allows the single hyphen to mark the end of the options, in addition to the use of the regular "--" argument, because it was considered that the older practice was so pervasive. An alternative approach is taken by the KornShell, where real and effective user/group IDs must match for an interactive shell; this behavior is specifically allowed by this volume of IEEE Std 1003.1-2001.

Note:
There are other problems with set-user-ID scripts that the two approaches described here do not resolve.
But still i am not able to understand what is it.I would appreciate if somebody can explain it in simple language.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Deleting directory with leading hyphen in name

I asked this question last month in Stack Exchange (linux - delete directory with leading hyphen - Server Fault) and none of the answers supplied worked. I have somehow created a directory with a leading hyphen and cannot get rid of it. # ls -li | grep p 2621441 drwxr-xr-x. 2 root root... (4 Replies)
Discussion started by: edstevens
4 Replies

2. Shell Programming and Scripting

Replacing space with hyphen in a pattern.

I have a huge text file, about 52 GB. In the file, there are patterns like these: ] ] ] ]One can see that there is text within patterns such as and ], and I am only interested in ]. There is text before and after all these patterns too, for example, ''Anarchism''' is a ] that advocates ]... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

3. Shell Programming and Scripting

Insert a hyphen between two delimiters using sed

Hey guys, I have a file that is delimited by | and I am trying to write a sed command to convert this: abc|def||ghi|jkl||||mnop into this: abc|def|-|ghi|jkl|-|-|-|mnop The output I am getting out of: sed -e "s/+//g" /tmp/opt.del > /tmp/opt2.del is like: ... (9 Replies)
Discussion started by: prohank
9 Replies

4. Shell Programming and Scripting

sed - replacing a substring containing a hyphen

I'm attempting to replace a substring that contains a hyphen and not having much success, can anyone point out where i'm going wrong or suggest an alternative. # echo /var/lib/libvirt/images/vm888b-clone.qcow | sed -e 's|vm888-clone|qaz|g' /var/lib/libvirt/images/vm888b-clone.qcow (1 Reply)
Discussion started by: squrcles
1 Replies

5. Shell Programming and Scripting

Grep command to ignore line starting with hyphen

Hi, I want to read a file line by line and exclude the lines that are beginning with special characters. The below code is working fine except when the line starts with hyphen (-) in the file. for TEST in `cat $FILE | grep -E -v '#|/+' | awk '{FS=":"}NF > 0{print $1}'` do . . done How... (4 Replies)
Discussion started by: Srinraj Rao
4 Replies

6. Shell Programming and Scripting

awk - replace first hyphen

How do I use awk to replace the first hyphen of a specific record? (1 Reply)
Discussion started by: locoroco
1 Replies

7. Shell Programming and Scripting

delete the last hyphen

I want to check for more than one hyphen and then hold the first one and delete the rest of the hyphen. I try something like this sed 's/\(*\)\1/\1/' but this doesn't work. I try something like this sed 's/\(*\)-\1/ \1/g' but here the script delete all the hyphen. I want to go from this : I... (2 Replies)
Discussion started by: thailand
2 Replies

8. UNIX Desktop Questions & Answers

How to remove text in each line after hyphen?

Hi, I'm trying to do something relatively simple. I have a txt file that has the following kinds of lines (and many more lines): CP19 Oahu - Maunawili Falls CP20 Oahu - Maunawili Falls AG12 Oahu - Maunawili Falls CP22 Oahu - Maunawili Falls, Local area AG14 Oahu CP141 KZ102 Kauai -... (7 Replies)
Discussion started by: euspilapteryx
7 Replies

9. Shell Programming and Scripting

Hyphen char after shebang notation

Hi, I have a trivial question to ask, I am seeing in some shell scripts the '-' (hyphen) character following the first line of shell script (i.e) the shebang notation as follows: #!/bin/sh - #! /bin/bash - what does the hyphen signify? What will happen if it is not given explicitly? (2 Replies)
Discussion started by: royalibrahim
2 Replies

10. Shell Programming and Scripting

add a hyphen every 2 characters of every line

I have a text file like this with hundreds of lines: >cat file1.txt 1027123000 1027124000 1127125000 1128140000 1228143000 > all lines are very similar and have exactly 10 digits. I want to separate the digits by twodigit and hyphens....like so, > 10-27-12-30-00 10-27-12-40-00... (7 Replies)
Discussion started by: ajp7701
7 Replies
Login or Register to Ask a Question