/b/ - Random

bad boy forum

[X]

Mark sensitive


File: d1edc541b066a3c4d5dca51165(...).gif (1.47 MB)
Anonymous 07/23/21(Fri)04:07:08 No. fb-9J42PY5O [Report]

Is it $CURRENT_YEAR yet?

>>
Anonymous 10/12/21(Tue)03:42:31 No. fb-5KWEMI0B [Report]

>>fb-9J42PY5O (OP) Zoomer "humor".

>>
Anonymous 10/12/21(Tue)05:22:26 No. fb-ZRRXJ7DW [Report] >>fb-SKQ75MKU

All for you, OP: ohyeah() { [ -n "$1" ] && local CURRENT_YEAR="$1" || read -p "What is the current year? " CURRENT_YEAR case "$CURRENT_YEAR" in 1999) echo "It's 1999! Let's party!" ;; *) echo "It's $CURRENT_YEAR." ;; esac } $ ohyeah 2021

>>
Anonymous 10/13/21(Wed)05:44:50 No. fb-SKQ75MKU [Report] >>fb-FOHBBMBP

>>fb-ZRRXJ7DW Minor niggle: If you use bash function ohyeah to set CURRENT_YEAR, it sets the variable in the global namespace with $CURRENT_YEAR remaining defined outside of the function. Here's a fixed version which doesn't do that, also able to use $CURRENT_YEAR set outside the function when no argument is provided. ohyeah() { local CURRENT_YEAR="${1:-$CURRENT_YEAR}" # To have the function set the variable globally, remove the "local" keyword. [ -z "$CURRENT_YEAR" ] && read -p "What is the current year? " CURRENT_YEAR [ -z "$CURRENT_YEAR" ] && echo "Bueller?" && return 1 # No answer was provided. case "$CURRENT_YEAR" in 1999) echo "It's 1999! Let's party!" ;; *) echo "It's $CURRENT_YEAR." ;; esac } Further improvements and additional case years are welcome! Should ohyeah become a GitHub project??? };^)

>>
Anonymous 10/13/21(Wed)05:58:53 No. fb-FOHBBMBP [Report]

>>fb-SKQ75MKU Oh, you can use case to check for an empty answer too, removing the need for two empty (-z) checks prior: case "$CURRENT_YEAR" in "") echo "Bueller?" && return 1 ;; # No answer was provided. ... /g/? What's that? :-)


[Post a Reply] 4 / 0

[Home] [Rules] [FAQ]

All trademarks and copyrights on this page are owned by their respective parties.

Theme: