PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Shell parameters question on $_ and $-
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Shell parameters question on $_ and $-

Réponse
 
LinkBack Outils de la discussion
Vieux 18/07/2007, 01h17   #1
nimdhar@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Shell parameters question on $_ and $-

What does the shell parameters $_ and $- mean? I get "himBH" as the
result for both the parameters on my mac (bash shell) What does the
set built in option flags himBH correspond to? Can some one point a
real world example of $_ and $- like the use of $?

  Réponse avec citation
Vieux 18/07/2007, 02h56   #2
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Shell parameters question on $_ and $-

On 2007-07-18, nimdhar@gmail.com wrote:
> What does the shell parameters $_ and $- mean? I get "himBH" as the
> result for both the parameters on my mac (bash shell) What does the
> set built in option flags himBH correspond to? Can some one point a
> real world example of $_ and $- like the use of $?


Read the 'Special Parameters' section of the bash man page:

- Expands to the current option flags as specified upon
invocation, by the set builtin command, or those set by the
shell itself (such as the -i option).

...

_ At shell startup, set to the absolute file name of the shell
or shell script being executed as passed in the argument
list. Subsequently, expands to the last argument to the
previous command, after expansion. Also set to the full file
name of each command executed and placed in the environment
exported to that command. When checking mail, this parameter
holds the name of the mail file currently being checked.


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 18/07/2007, 02h56   #3
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Shell parameters question on $_ and $-

On 2007-07-18, nimdhar@gmail.com wrote:
> What does the shell parameters $_ and $- mean? I get "himBH" as the
> result for both the parameters on my mac (bash shell) What does the
> set built in option flags himBH correspond to? Can some one point a
> real world example of $_ and $- like the use of $?


Read the 'Special Parameters' section of the bash man page:

- Expands to the current option flags as specified upon
invocation, by the set builtin command, or those set by the
shell itself (such as the -i option).

...

_ At shell startup, set to the absolute file name of the shell
or shell script being executed as passed in the argument
list. Subsequently, expands to the last argument to the
previous command, after expansion. Also set to the full file
name of each command executed and placed in the environment
exported to that command. When checking mail, this parameter
holds the name of the mail file currently being checked.


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 18/07/2007, 14h04   #4
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Shell parameters question on $_ and $-

On Wed, 18 Jul 2007 00:17:44 -0000, nimdhar@gmail.com
<nimdhar@gmail.com> wrote:
>
>
> What does the shell parameters $_ and $- mean? I get "himBH" as the
> result for both the parameters on my mac (bash shell) What does the
> set built in option flags himBH correspond to? Can some one point a
> real world example of $_ and $- like the use of $?


'man bash' can explain what the letters himBH mean, if you search for
' -h', ' -i' and so on. '$-' contains a list of single letter
options, which is most often used to see if it contains 'i' for an
interactive shell. Bash has many other options which you can query or
set with the commands 'set -o' and 'shopt'.
'$_' at the command prompt is the last argument of the previous command.
Search for ' _' in 'man bash' for a more complete explanation.

--
Your friends will know you better in the first minute you meet than your
acquaintances will know you in a thousand years.
-- Richard Bach, "Illusions"
  Réponse avec citation
Vieux 18/07/2007, 17h07   #5
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Shell parameters question on $_ and $-

2007-07-17, 21:56(-04), Chris F.A. Johnson:
[...]
> _ At shell startup, set to the absolute file name of the shell
> or shell script being executed as passed in the argument
> list.


That would be a documentation bug, then.

What I observe is that, if such a variable is passed in bash's
environment, them bash leaves it untouched:

$ env _=blah bash -c 'echo $_'
blah

If there's no _ passed in bash's environment, then I find it to
be the shell's argv[0]. So, that would be the script path only
if the system (in case of #!) or user (in case of exec of bash)
was setting bash's argv[0] as the full pathname of the script.
According to Sven Mascheck shebang site, only Munix and very old
versions of HPUX may exhibit such a behavior.

--
Stéphane
  Réponse avec citation
Vieux 19/07/2007, 09h10   #6
Ben
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Shell parameters question on $_ and $-

Hello,

I have experimented with something.

First
$touch foo
$touch - // What actually happens with this command? Shell expansion
or a file named "-"?
// now I do actually get a file named "-", but rm "-" doesn't get rid
of it... Anyone knows what has happened? How do I delete the file?

Cheers.
Benson

On Jul 18, 2:56 am, "Chris F.A. Johnson" <cfajohn...@gmail.com> wrote:
> On 2007-07-18, nimd...@gmail.com wrote:
> > What does the shell parameters $_ and $- mean? I get "himBH" as the
> > result for both the parameters on my mac (bash shell) What does the
> > set built in option flags himBH correspond to? Can some one point a
> > real world example of $_ and $- like the use of $?

>
> Read the 'Special Parameters' section of the bash man page:
>
> - Expands to the current option flags as specified upon
> invocation, by the set builtin command, or those set by the
> shell itself (such as the -i option).
>
> ...
>
> _ At shell startup, set to the absolute file name of the shell
> or shell script being executed as passed in the argument
> list. Subsequently, expands to the last argument to the
> previous command, after expansion. Also set to the full file
> name of each command executed and placed in the environment
> exported to that command. When checking mail, this parameter
> holds the name of the mail file currently being checked.
>
> --
> Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
> ===== My code in this post, if any, assumes the POSIX locale
> ===== and is released under the GNU General Public Licence



  Réponse avec citation
Vieux 19/07/2007, 17h04   #7
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Shell parameters question on $_ and $-

On Thu, 19 Jul 2007 01:10:04 -0700, Ben
<chinese.central@googlemail.com> wrote:
>
>
> Hello,
>
> I have experimented with something.
>
> First
> $touch foo
> $touch - // What actually happens with this command? Shell expansion
> or a file named "-"?
> // now I do actually get a file named "-", but rm "-" doesn't get rid
> of it... Anyone knows what has happened? How do I delete the file?
>

rm ./- or rm -- -


--
purpitation, n.:
To take something off the grocery shelf, decide you
don't want it, and then put it in another section.
-- "Sniglets", Rich Hall & Friends
  Réponse avec citation
Vieux 19/07/2007, 17h35   #8
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Shell parameters question on $_ and $-

On 2007-07-19, Ben wrote:
> Hello,
>
> I have experimented with something.
>
> First
> $touch foo
> $touch - // What actually happens with this command? Shell expansion
> or a file named "-"?


Why would there be shell expansion? You didn't use $-.

> // now I do actually get a file named "-", but rm "-" doesn't get rid
> of it...


It works for me.

> Anyone knows what has happened? How do I delete the file?


Take your pick:

rm -- -
rm ./-
rm [-]

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 19/07/2007, 22h41   #9
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Shell parameters question on $_ and $-

2007-07-19, 12:35(-04), Chris F.A. Johnson:
[...]
> Take your pick:
>
> rm -- -
> rm ./-
> rm [-]


rm [-]

won't .

If there's a file called "-", the shell will expand that to

rm -

if not (except where that wrong behavior has been fixed like in
csh, tcsh and zsh), it will try to delete the file called [-].

--
Stéphane
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h18.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18655 seconds with 17 queries