The bash script does many things. However, at beginning it should start if the input passed to the script is a directory path. For example, right way of telling directory path is "/var/lib/test", and incorrect way is "/var/%%^?/test".
where test is a directory and not a file.
The directory path can contain characters. [A-Za-z0-9/_-]
My script is as below -
#!/bin/bash
dirPath="/var/lib/test"
if [[ ! ${dirPath} =~ "^/[A-Za-z0-9/_-]+$" ]]; then
echo "Success"
else
echo "Failure"
fi
Here, dirPath can have any path provided from another script.
please let me know the error here.
Success. Is that expected? Can you give some examples of when it should returnFailureandSuccess?/var/%%^?/testis a valid pathname on Unix. Would it be enough to test whether the given path denotes an existing directory?[...]in a regular expression, there are no delimiters. Even backslashes would be taken as literal backslashes.=~doesn't take slashes to delimit the regex