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?
Are Finite Automata Turing Complete?
How can I convince my reader that I will not use a certain trope?
Is my Rep in Stack-Exchange Form?
Short story with brother-sister conjoined twins as protagonists?
Alphabet completion rate
What do you call the action of someone tackling a stronger person?
Symbolic equivalent of chmod 400
Layout of complex table
Simple object validator with a new API
What is the line crossing the Pacific Ocean that is shown on maps?
Was touching your nose a greeting in second millenium Mesopotamia?
What would Earth look like at night in medieval times?
Do sudoku answers always have a single minimal clue set?
Why does the A-4 Skyhawk sit nose-up when on ground?
Why does the numerical solution of an ODE move away from an unstable equilibrium?
Is adding a new player (or players) a DM decision, or a group decision?
Why is the Turkish president's surname spelt in Russian as Эрдоган, with г?
Are there any vegetarian astronauts?
Is this one of the engines from the 9/11 aircraft?
Should I tell my insurance company I'm making payments on my new car?
C-152 carb heat on before landing in hot weather?
Should my manager be aware of private LinkedIn approaches I receive? How to politely have this happen?
How should I behave to assure my friends that I am not after their money?
What is this blowing instrument used in the acoustic cover of "Taekwondo" by "Walk off the Earth"?
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
9 hours ago
I thought it might loop round like some arrays do. Thanks.
– Neil
9 hours ago
Possible duplicate of Meaning of a hyphen as a special parameter?
– muru
9 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 6 hours ago
Jeff Schaller♦
47.1k11 gold badges68 silver badges153 bronze badges
47.1k11 gold badges68 silver badges153 bronze badges
asked 9 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
9 hours ago
I thought it might loop round like some arrays do. Thanks.
– Neil
9 hours ago
Possible duplicate of Meaning of a hyphen as a special parameter?
– muru
9 hours ago
add a comment |
1
$-
gets the current shell options (which is apparently "hb"). What did you expect it to do?
– Gordon Davisson
9 hours ago
I thought it might loop round like some arrays do. Thanks.
– Neil
9 hours ago
Possible duplicate of Meaning of a hyphen as a special parameter?
– muru
9 hours ago
1
1
$-
gets the current shell options (which is apparently "hb"). What did you expect it to do?– Gordon Davisson
9 hours ago
$-
gets the current shell options (which is apparently "hb"). What did you expect it to do?– Gordon Davisson
9 hours ago
I thought it might loop round like some arrays do. Thanks.
– Neil
9 hours ago
I thought it might loop round like some arrays do. Thanks.
– Neil
9 hours ago
Possible duplicate of Meaning of a hyphen as a special parameter?
– muru
9 hours ago
Possible duplicate of Meaning of a hyphen as a special parameter?
– muru
9 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
9 hours ago
1
Hmmm:$@:~0
andeval echo $$#
are also the last argument. :-)
– Isaac
8 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
9 hours ago
1
Hmmm:$@:~0
andeval echo $$#
are also the last argument. :-)
– Isaac
8 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
9 hours ago
1
Hmmm:$@:~0
andeval echo $$#
are also the last argument. :-)
– Isaac
8 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 9 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
9 hours ago
1
Hmmm:$@:~0
andeval echo $$#
are also the last argument. :-)
– Isaac
8 hours ago
add a comment |
4
$!#
is also the value of the last parameter, using indirect expansion.
– glenn jackman
9 hours ago
1
Hmmm:$@:~0
andeval echo $$#
are also the last argument. :-)
– Isaac
8 hours ago
4
4
$!#
is also the value of the last parameter, using indirect expansion.– glenn jackman
9 hours ago
$!#
is also the value of the last parameter, using indirect expansion.– glenn jackman
9 hours ago
1
1
Hmmm:
$@:~0
and eval echo $$#
are also the last argument. :-)– Isaac
8 hours ago
Hmmm:
$@:~0
and eval echo $$#
are also the last argument. :-)– Isaac
8 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
9 hours ago
I thought it might loop round like some arrays do. Thanks.
– Neil
9 hours ago
Possible duplicate of Meaning of a hyphen as a special parameter?
– muru
9 hours ago