Skip to main content
Post Undeleted by terdon
Post Deleted by CommunityBot
reduced obscurity in the sample call to script 'foo', and code-quoted a few more little fragments
Source Link
user56373
user56373

which shows the fairly rare occasion to use ${NAME}${NAME} instead of simply $NAME$NAME - to separate the variable name from any letter following. In fact, if you didn't have a trailing / on the definition of ROOT, I'd be writing

foo program-x "attached is the software" "please read the accompanying manual"

then foofoo will see -x as $1, and the two strings as $2$2 and $3 $3 (which you should access as "$2""$2" and "$3""$3" for obvious reasons). If, however, you want to pass this entire set of parameters to another script, the following will suffer horrible splitting on all the spaces:

It's kinda entertaining to experiment with other effects of $@$@ when not used as "$@""$@" but you'll quickly find out it's not actually that entertaining... it is merely a special case that solves a major problem.

which shows the fairly rare occasion to use ${NAME} instead of simply $NAME - to separate the variable name from any letter following. In fact, if you didn't have a trailing / on the definition of ROOT, I'd be writing

foo program "attached is the software" "please read the accompanying manual"

then foo will see the two strings as $2 and $3 (which you should access as "$2" and "$3" for obvious reasons). If, however, you want to pass this entire set of parameters to another script, the following will suffer horrible splitting on all the spaces:

It's kinda entertaining to experiment with other effects of $@ when not used as "$@" but you'll quickly find out it's not actually that entertaining... it is merely a special case that solves a major problem.

which shows the fairly rare occasion to use ${NAME} instead of simply $NAME - to separate the variable name from any letter following. In fact, if you didn't have a trailing / on the definition of ROOT, I'd be writing

foo -x "attached is the software" "please read the accompanying manual"

then foo will see -x as $1, and the two strings as $2 and $3 (which you should access as "$2" and "$3" for obvious reasons). If, however, you want to pass this entire set of parameters to another script, the following will suffer horrible splitting on all the spaces:

It's kinda entertaining to experiment with other effects of $@ when not used as "$@" but you'll quickly find out it's not actually that entertaining... it is merely a special case that solves a major problem.

added 10 characters in body
Source Link
user56373
user56373

One further point that's related and well worth knowing about: the distinction between $, $@, "$"$*, $@, "$*" and "$@""$@". So I'll talk about it!

which deliberately quotes the individual members of $*$* as complete quoted strings but keeps them separate. Everyone is a winner now.

One further point that's related and well worth knowing about: the distinction between $, $@, "$" and "$@". So I'll talk about it!

which deliberately quotes the individual members of $* as complete quoted strings but keeps them separate. Everyone is a winner now.

One further point that's related and well worth knowing about: the distinction between $*, $@, "$*" and "$@". So I'll talk about it!

which deliberately quotes the individual members of $* as complete quoted strings but keeps them separate. Everyone is a winner now.

added 22 characters in body
Source Link
user56373
user56373

which shows the fairly rare occasion to use ${NAME} instead of simply $NAME - once again to reduce visual noiseseparate the variable name from any letter following. In fact, if you didn't have a trailing / on the definition of ROOT, I'd be writing

which shows the fairly rare occasion to use ${NAME} instead of simply $NAME - once again to reduce visual noise. In fact, if you didn't have a trailing / on the definition of ROOT, I'd be writing

which shows the fairly rare occasion to use ${NAME} instead of simply $NAME - to separate the variable name from any letter following. In fact, if you didn't have a trailing / on the definition of ROOT, I'd be writing

Source Link
user56373
user56373
Loading