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;








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















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








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












  • 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










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
    9 hours ago






  • 1





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

    – Isaac
    8 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
    9 hours ago






  • 1





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

    – Isaac
    8 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
    9 hours ago






  • 1





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

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

    – Isaac
    8 hours ago












  • 4





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

    – glenn jackman
    9 hours ago






  • 1





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

















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

ParseJSON using SSJSUsing AMPscript with SSJS ActivitiesHow to resubscribe a user in Marketing cloud using SSJS?Pulling Subscriber Status from Lists using SSJSRetrieving Emails using SSJSProblem in updating DE using SSJSUsing SSJS to send single email in Marketing CloudError adding EmailSendDefinition using SSJS

Кампала Садржај Географија Географија Историја Становништво Привреда Партнерски градови Референце Спољашње везе Мени за навигацију0°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.340°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.34МедијиПодациЗванични веб-сајту

19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу