Which regular expression methods to validate input could be used in shell scripting?
7
votes
3
answers
3706
views
#!/bin/sh
re="\/$"
if [ $1 =~ $re ]; then
echo "${ATTENTION_PREFIX}$1 DIRECTORY MAY NOT CONTAIN A \"/\" OR LITERAL SLASH!${ATTENTION_POSTFIX}"
exit 1
fi
Executing
./file.sh hello/
results in [: 29: hello: unexpected operator
It looks like that this regular expression method is incorrect for shell scripting.
Asked by 030
(1588 rep)
Jul 4, 2014, 08:22 AM
Last activity: Oct 7, 2023, 05:05 PM
Last activity: Oct 7, 2023, 05:05 PM