Monday, April 29, 2024
33
rated 0 times [  33] [ 0]  / answers: 1 / hits: 7144  / 1 Year ago, sun, february 5, 2023, 4:10:12

I have this line in my .bashrc and I would like to know what exactly this means



# If not running interactively, don't do anything
[[ $- != *i* ]] && return

More From » command-line

 Answers
7

  • $- means 'current flags'.

  • echo $- returns "himBH". Those are all defaults.

  • so ... [[ $- != *i* ]] && return actually does what it says above in a comment: it checks if the interactive flag is set. The [[ and ]] make it a boolean so it ends up in a "true" or "false". "false && return" makes it go on "true && return" makes it execute the return.



The default flags explained in more detail:



h is for "hash all": this tells bash to remember the locations of commands it has found through querying your PATH.



i is for "interactive": entering input & getting back output.



m is for "monitor": this enables job control



B is for "brace expand". This allows you to use brace expansion



H is for "history expand". This is what enables you to rerun a command from your history by prefacing its number with an exclamation point






By the way. I have ...



# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac


Basically does the same but easier to read I assume.


[#13610] Sunday, February 5, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ntlesslving

Total Points: 123
Total Questions: 109
Total Answers: 113

Location: South Korea
Member since Fri, Sep 11, 2020
4 Years ago
;