Bash echo $-1 prints hb1. Why?Meaning of a hyphen as a special parameter?Why did BASH print “bash: cd: write error: Success”?Explain this bash script: echo “$1##*.”why 'echo --help' doesn't give me help page of echo?Bash - syntax in echoNested echo command in backticksWhy does `bash -c 'echo $0 ' ` output “bash”?bash script to echo wan ipWhy is echo $SHELL always showing /bin/bash?bash - echo prints to the terminalCan't pipe from echo to bash built-in read?
Could Sauron have read Tom Bombadil's mind if Tom had held the Palantir?
Ending: accusative or not?
Is adding a new player (or players) a DM decision, or a group decision?
Why aren't (poly-)cotton tents more popular?
"It will become the talk of Paris" - translation into French
Inverse-quotes-quine
When is it ok to add filler to a story?
Analog is Obtuse!
Why is the Turkish president's surname spelt in Russian as Эрдоган, with г?
What do you call the action of someone tackling a stronger person?
Why cruise at 7000' in an A319?
C-152 carb heat on before landing in hot weather?
Do equal angles necessarily mean a polygon is regular?
In the Marvel universe, can a human have a baby with any non-human?
Finding closed forms for various addition laws on elliptic curves, FullSimplify fails even with assumptions?
Syntax Error with 'if'
Should I include salary information on my CV?
A player is constantly pestering me about rules, what do I do as a DM?
Links to webpages in books
Why does the numerical solution of an ODE move away from an unstable equilibrium?
Why does adding parentheses prevent an error?
Should I tell my insurance company I'm making payments on my new car?
Symbolic equivalent of chmod 400
What are the penalties for overstaying in USA?
Bash echo $-1 prints hb1. Why?
Meaning of a hyphen as a special parameter?Why did BASH print “bash: cd: write error: Success”?Explain this bash script: echo “$1##*.”why 'echo --help' doesn't give me help page of echo?Bash - syntax in echoNested echo command in backticksWhy does `bash -c 'echo $0 ' ` output “bash”?bash script to echo wan ipWhy is echo $SHELL always showing /bin/bash?bash - echo prints to the terminalCan't pipe from echo to bash built-in read?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
If I ask bash to echo the -1th argument it prints hb1:
echo $-1
hb1
Why? What is it accessing?
bash arguments
add a comment |
If I ask bash to echo the -1th argument it prints hb1:
echo $-1
hb1
Why? What is it accessing?
bash arguments
1
$-
gets the current shell options (which is apparently "hb"). What did you expect it to do?
– Gordon Davisson
8 hours ago
I thought it might loop round like some arrays do. Thanks.
– Neil
8 hours ago
Possible duplicate of Meaning of a hyphen as a special parameter?
– muru
8 hours ago
add a comment |
If I ask bash to echo the -1th argument it prints hb1:
echo $-1
hb1
Why? What is it accessing?
bash arguments
If I ask bash to echo the -1th argument it prints hb1:
echo $-1
hb1
Why? What is it accessing?
bash arguments
bash arguments
edited 5 hours ago
Jeff Schaller♦
47.1k11 gold badges68 silver badges153 bronze badges
47.1k11 gold badges68 silver badges153 bronze badges
asked 8 hours ago
NeilNeil
1083 bronze badges
1083 bronze badges
1
$-
gets the current shell options (which is apparently "hb"). What did you expect it to do?
– Gordon Davisson
8 hours ago
I thought it might loop round like some arrays do. Thanks.
– Neil
8 hours ago
Possible duplicate of Meaning of a hyphen as a special parameter?
– muru
8 hours ago
add a comment |
1
$-
gets the current shell options (which is apparently "hb"). What did you expect it to do?
– Gordon Davisson
8 hours ago
I thought it might loop round like some arrays do. Thanks.
– Neil
8 hours ago
Possible duplicate of Meaning of a hyphen as a special parameter?
– muru
8 hours ago
1
1
$-
gets the current shell options (which is apparently "hb"). What did you expect it to do?– Gordon Davisson
8 hours ago
$-
gets the current shell options (which is apparently "hb"). What did you expect it to do?– Gordon Davisson
8 hours ago
I thought it might loop round like some arrays do. Thanks.
– Neil
8 hours ago
I thought it might loop round like some arrays do. Thanks.
– Neil
8 hours ago
Possible duplicate of Meaning of a hyphen as a special parameter?
– muru
8 hours ago
Possible duplicate of Meaning of a hyphen as a special parameter?
– muru
8 hours ago
add a comment |
1 Answer
1
active
oldest
votes
You are not asking it to print the 1st argument, that would be: $1
.
What you are asking for is a special parameter:
-
(
$-
, a hyphen.) 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).
So your options are: hb
Then you see the 1
you've added is printed afterwards (hence hb1
).
If you are looking to get the last argument (Not sure if that is what you meant by -1 argument), you can use Shell Parameter Expansion in the following form:
$ set -- one two three
$ echo "$@: -1"
three
4
$!#
is also the value of the last parameter, using indirect expansion.
– glenn jackman
8 hours ago
1
Hmmm:$@:~0
andeval echo $$#
are also the last argument. :-)
– Isaac
7 hours ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f526419%2fbash-echo-1-prints-hb1-why%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are not asking it to print the 1st argument, that would be: $1
.
What you are asking for is a special parameter:
-
(
$-
, a hyphen.) 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).
So your options are: hb
Then you see the 1
you've added is printed afterwards (hence hb1
).
If you are looking to get the last argument (Not sure if that is what you meant by -1 argument), you can use Shell Parameter Expansion in the following form:
$ set -- one two three
$ echo "$@: -1"
three
4
$!#
is also the value of the last parameter, using indirect expansion.
– glenn jackman
8 hours ago
1
Hmmm:$@:~0
andeval echo $$#
are also the last argument. :-)
– Isaac
7 hours ago
add a comment |
You are not asking it to print the 1st argument, that would be: $1
.
What you are asking for is a special parameter:
-
(
$-
, a hyphen.) 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).
So your options are: hb
Then you see the 1
you've added is printed afterwards (hence hb1
).
If you are looking to get the last argument (Not sure if that is what you meant by -1 argument), you can use Shell Parameter Expansion in the following form:
$ set -- one two three
$ echo "$@: -1"
three
4
$!#
is also the value of the last parameter, using indirect expansion.
– glenn jackman
8 hours ago
1
Hmmm:$@:~0
andeval echo $$#
are also the last argument. :-)
– Isaac
7 hours ago
add a comment |
You are not asking it to print the 1st argument, that would be: $1
.
What you are asking for is a special parameter:
-
(
$-
, a hyphen.) 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).
So your options are: hb
Then you see the 1
you've added is printed afterwards (hence hb1
).
If you are looking to get the last argument (Not sure if that is what you meant by -1 argument), you can use Shell Parameter Expansion in the following form:
$ set -- one two three
$ echo "$@: -1"
three
You are not asking it to print the 1st argument, that would be: $1
.
What you are asking for is a special parameter:
-
(
$-
, a hyphen.) 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).
So your options are: hb
Then you see the 1
you've added is printed afterwards (hence hb1
).
If you are looking to get the last argument (Not sure if that is what you meant by -1 argument), you can use Shell Parameter Expansion in the following form:
$ set -- one two three
$ echo "$@: -1"
three
answered 8 hours ago
Jesse_bJesse_b
17.1k3 gold badges42 silver badges84 bronze badges
17.1k3 gold badges42 silver badges84 bronze badges
4
$!#
is also the value of the last parameter, using indirect expansion.
– glenn jackman
8 hours ago
1
Hmmm:$@:~0
andeval echo $$#
are also the last argument. :-)
– Isaac
7 hours ago
add a comment |
4
$!#
is also the value of the last parameter, using indirect expansion.
– glenn jackman
8 hours ago
1
Hmmm:$@:~0
andeval echo $$#
are also the last argument. :-)
– Isaac
7 hours ago
4
4
$!#
is also the value of the last parameter, using indirect expansion.– glenn jackman
8 hours ago
$!#
is also the value of the last parameter, using indirect expansion.– glenn jackman
8 hours ago
1
1
Hmmm:
$@:~0
and eval echo $$#
are also the last argument. :-)– Isaac
7 hours ago
Hmmm:
$@:~0
and eval echo $$#
are also the last argument. :-)– Isaac
7 hours ago
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f526419%2fbash-echo-1-prints-hb1-why%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
$-
gets the current shell options (which is apparently "hb"). What did you expect it to do?– Gordon Davisson
8 hours ago
I thought it might loop round like some arrays do. Thanks.
– Neil
8 hours ago
Possible duplicate of Meaning of a hyphen as a special parameter?
– muru
8 hours ago