Enhanced exep() incl api help
New helper function escpath() incl api help
This commit is contained in:
@@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
## Version information
|
## Version information
|
||||||
|
|
||||||
VERSION_REV=14
|
VERSION_REV=15
|
||||||
VERSION_MAJOR=0
|
VERSION_MAJOR=0
|
||||||
VERSION_MINOR=2
|
VERSION_MINOR=0
|
||||||
|
|
||||||
## Start of generic script part
|
## Start of generic script part
|
||||||
|
|
||||||
@@ -144,13 +144,23 @@ cat <<USAGE_API
|
|||||||
verbose (-v): print command before execution
|
verbose (-v): print command before execution
|
||||||
|
|
||||||
USAGE_API
|
USAGE_API
|
||||||
echo -e "${GREEN} exep \"[COMMANDLINE]\"${NC}"
|
echo -e "${GREEN} exep \"[COMMAND STRING(s)]\"${NC}"
|
||||||
cat <<USAGE_API
|
cat <<USAGE_API
|
||||||
See exe, but support for pipes or redirects.
|
See exe, but support for pipes or redirects.
|
||||||
|
e.g.: exep echo hello world \\> \\'out put.log\\'
|
||||||
|
exep echo hello world \\> out\\\\ put.log
|
||||||
|
exep "echo hello world > 'out put.log'"
|
||||||
|
exep "echo hello world > out\\ put.log"
|
||||||
Important:
|
Important:
|
||||||
- Shell commands cd, read, ... won't work because COMMANDLINE is started in a new shell.
|
- Shell commands cd, read, ... won't work because [COMMAND STRING(s)] is started in a new shell.
|
||||||
- All apostrophes need to be esacped since the command line is given as string.
|
- All apostrophes need to be esacped since the command line is given as string.
|
||||||
|
|
||||||
|
USAGE_API
|
||||||
|
echo -e "${GREEN} escpath <PATH>${NC}"
|
||||||
|
cat <<USAGE_API
|
||||||
|
Escaping non-printable characters with the proposed POSIX $'' syntax
|
||||||
|
e.g. \$(escpath /my own/ho me/path) = $(escpath /my own/ho me/path)
|
||||||
|
|
||||||
USAGE_API
|
USAGE_API
|
||||||
echo -e "${GREEN} initSeqConfig [OPTION] <NAME> [TEMPLATE]${NC}"
|
echo -e "${GREEN} initSeqConfig [OPTION] <NAME> [TEMPLATE]${NC}"
|
||||||
cat <<USAGE_API
|
cat <<USAGE_API
|
||||||
@@ -345,6 +355,11 @@ echoinfoArgs() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Escaping non-printable characters with the proposed POSIX $'' syntax
|
||||||
|
escpath() {
|
||||||
|
printf "%q" "$*"
|
||||||
|
}
|
||||||
|
|
||||||
# endCheckEmpty <VariableName> [DESCRIPTION]
|
# endCheckEmpty <VariableName> [DESCRIPTION]
|
||||||
# DESCRIPTION : Optional text for error
|
# DESCRIPTION : Optional text for error
|
||||||
endCheckEmpty() {
|
endCheckEmpty() {
|
||||||
@@ -1101,30 +1116,29 @@ showVersion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exe() {
|
exe() {
|
||||||
local arr=("$@")
|
|
||||||
if [ $DRY -ne 0 ] ; then
|
if [ $DRY -ne 0 ] ; then
|
||||||
echo -n "--"
|
echo -n "--"
|
||||||
fi
|
fi
|
||||||
if [ $DRY -ne 0 ] || [ $VERBOSE -eq 1 ] ; then
|
if [ $DRY -ne 0 ] || [ $VERBOSE -eq 1 ] ; then
|
||||||
(set -x; : "${arr[@]}")
|
(set -x; : "$@")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $DRY -eq 0 ] ; then
|
if [ $DRY -eq 0 ] ; then
|
||||||
"${arr[@]}"
|
"$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Handle dry run and verbose output for commands containing pipe and/or redirects
|
# Handle dry run and verbose output for commands containing pipe and/or redirects
|
||||||
# exep <COMMAND TO RUN AS STRING>
|
# exep <COMMAND AS STRING(S)>
|
||||||
exep() {
|
exep() {
|
||||||
if [ $DRY -ne 0 ] ; then
|
if [ $DRY -ne 0 ] ; then
|
||||||
echo "--++ : $1"
|
echo "--++ : $*"
|
||||||
elif [ $VERBOSE -eq 1 ] ; then
|
elif [ $VERBOSE -eq 1 ] ; then
|
||||||
echo "++ : $1"
|
echo "++ : $*"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $DRY -eq 0 ] ; then
|
if [ $DRY -eq 0 ] ; then
|
||||||
bash -c "$1"
|
bash -c "$*"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user