use conditional in bash script to check string argument
By : Thomas Mantay
Date : March 29 2020, 07:55 AM
To fix this issue I am trying to write my shell script thing.sh so that upon making it an executable and running it with the single letter ``A" like so: , What about the shorter : code :
#!/bin/bash
[[ $1 == A ]] && echo "A" || echo "not A"
#!/bin/bash
if [[ $1 == A ]]; then
echo "A"
else
echo "not A"
fi
|
How to check if the argument passed is a string in c?
By : Rupesh
Date : March 29 2020, 07:55 AM
will be helpful for those in need what I want is that if someone passes a string than I give an error
|
How to check if an argument is a string in unix
By : 陈月阳
Date : March 29 2020, 07:55 AM
seems to work fine If you want to know if a particular argument is a string, the answer is "yes". All arguments are strings. If you want to know if an argument is a particular string, check it: code :
for arg; do
if test "$arg" = incr; then
echo incr is passed as an argument
fi
done
|
Check if type can be an argument to boost::lexical_cast<string>
By : AĦmệd Kặŝệm
Date : November 22 2020, 01:01 AM
hop of those help? Your expression is not sufficient, as the lexical_cast function template takes everything and only reports errors via an internal static_assert. Instead test whether inserting the object into an std::ostream is valid: code :
template <typename T, typename=void>
struct IsLexCastable : std::false_type {};
// Can be extended to consider std::wostream as well for completeness
template <typename T>
struct IsLexCastable<T,
decltype(void(std::declval<std::ostream&>() << std::declval<T>()))>
: std::true_type {};
|
How can I check if the value of argument provided from GETOPTS is equal to specific string?
By : neekro
Date : March 29 2020, 07:55 AM
This might help you So really the only change you need to make is to change your ((...)) statement to a [[ ... ]] statement as @Nahuel Fouilleul suggested and add $'s to your destination variables. Their suggestion didn't work for you however because destination was spelled wrong. I have the updated code shown below. code :
#!/bin/bash
usage() { echo "Usage: $0 [-m < local|remote>]" 1>&2; exit 1; }
while getopts "m:" o; do
case "${o}" in
m)
destination=${OPTARG}
[[ $destination == "local" || $destination == "remote" ]] || usage
;;
*)
usage
;;
esac
done
shift "$(( OPTIND-1 ))"
echo $destination
...
m)
destination=${OPTARG}
;;
...
[[ ${destination:?A destination is required.} == "local" || ${destination} == "remote" ]] || usage
echo $destination
|