|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 $? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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" |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|