Skip to main content
deleted 2 characters in body
Source Link
rybo111
  • 12.6k
  • 4
  • 64
  • 74

The accepted solution checks whether parameters wherewere set by testing against the count of parameters given. If this is not the desired check, that is, if you want to check instead whether a specific parameter was set, the following would do it:

for i in "$@" ; do if [[ $i == "check parameter" ]] ; then echo "Is set!" break fi done 

Or, more compactly,:

for i in "$@" ; do [[ $i == "check argument" ]] && echo "Is set!" && break ; done 

The accepted solution checks whether parameters where set by testing against the count of parameters given. If this is not the desired check, that is, if you want to check instead whether a specific parameter was set, the following would do it:

for i in "$@" ; do if [[ $i == "check parameter" ]] ; then echo "Is set!" break fi done 

Or, more compactly,

for i in "$@" ; do [[ $i == "check argument" ]] && echo "Is set!" && break ; done 

The accepted solution checks whether parameters were set by testing against the count of parameters given. If this is not the desired check, that is, if you want to check instead whether a specific parameter was set, the following would do it:

for i in "$@" ; do if [[ $i == "check parameter" ]] ; then echo "Is set!" break fi done 

Or, more compactly:

for i in "$@" ; do [[ $i == "check argument" ]] && echo "Is set!" && break ; done 
improve code based on comment
Source Link
h7r
  • 5.1k
  • 2
  • 30
  • 31

The accepted solution checks whether parameters where set by testing against the count of parameters given. If this is not the desired check, that is, if you want to check instead whether a specific parameter was set, the following would do it:

for i in "$@" ; do if [[ "$@"$i == "check parameter" ]] ; then echo "parameter was echo "Is set!" break  fi done 

Or, more compactly,

[[for i in "$@" ; do [[ $i == "check parameter"argument" ]] && echo "Is set!" && break ; done 

The accepted solution checks whether parameters where set by testing against the count of parameters given. If this is not the desired check, that is, if you want to check instead whether a specific parameter was set, the following would do it:

if [[ "$@" == "check parameter" ]] ; then echo "parameter was set fi 

Or, more compactly,

[[ "$@" == "check parameter" ]] && echo "Is set!" 

The accepted solution checks whether parameters where set by testing against the count of parameters given. If this is not the desired check, that is, if you want to check instead whether a specific parameter was set, the following would do it:

for i in "$@" ; do if [[ $i == "check parameter" ]] ; then  echo "Is set!" break  fi done 

Or, more compactly,

for i in "$@" ; do [[ $i == "check argument" ]] && echo "Is set!" && break ; done 
Source Link
h7r
  • 5.1k
  • 2
  • 30
  • 31

The accepted solution checks whether parameters where set by testing against the count of parameters given. If this is not the desired check, that is, if you want to check instead whether a specific parameter was set, the following would do it:

if [[ "$@" == "check parameter" ]] ; then echo "parameter was set fi 

Or, more compactly,

[[ "$@" == "check parameter" ]] && echo "Is set!"