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;








1















If I ask bash to echo the -1th argument it prints hb1:



echo $-1
hb1


Why? What is it accessing?










share|improve this question



















  • 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















If I ask bash to echo the -1th argument it prints hb1:



echo $-1
hb1


Why? What is it accessing?










share|improve this question



















  • 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








1








If I ask bash to echo the -1th argument it prints hb1:



echo $-1
hb1


Why? What is it accessing?










share|improve this question
















If I ask bash to echo the -1th argument it prints hb1:



echo $-1
hb1


Why? What is it accessing?







bash arguments






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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










1 Answer
1






active

oldest

votes


















10














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





share|improve this answer


















  • 4





    $!# is also the value of the last parameter, using indirect expansion.

    – glenn jackman
    8 hours ago






  • 1





    Hmmm: $@:~0 and eval echo $$# are also the last argument. :-)

    – Isaac
    7 hours ago













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
);



);













draft saved

draft discarded


















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









10














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





share|improve this answer


















  • 4





    $!# is also the value of the last parameter, using indirect expansion.

    – glenn jackman
    8 hours ago






  • 1





    Hmmm: $@:~0 and eval echo $$# are also the last argument. :-)

    – Isaac
    7 hours ago















10














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





share|improve this answer


















  • 4





    $!# is also the value of the last parameter, using indirect expansion.

    – glenn jackman
    8 hours ago






  • 1





    Hmmm: $@:~0 and eval echo $$# are also the last argument. :-)

    – Isaac
    7 hours ago













10












10








10







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





share|improve this answer













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






share|improve this answer












share|improve this answer



share|improve this answer










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 and eval echo $$# are also the last argument. :-)

    – Isaac
    7 hours ago












  • 4





    $!# is also the value of the last parameter, using indirect expansion.

    – glenn jackman
    8 hours ago






  • 1





    Hmmm: $@:~0 and eval 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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її