Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active August 29, 2022 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/71255f60a4d26f0e8ffe8cd8ca9a100f to your computer and use it in GitHub Desktop.
Save guitarrapc/71255f60a4d26f0e8ffe8cd8ca9a100f to your computer and use it in GitHub Desktop.
CLIBS = ""
foo:
@echo "CLIBS is '${CLIBS}'"
#!/bin/bash
set -e
# echo command & execute
foo() {
echo "$*"
eval "$*"
}
# echo command & execute without escape.
foo2() {
echo "$*"
"$@"
}
libs="-L/usr/local/lib -L/lib/x86_64-linux-gnu/"
# Just want to add `foo` function but quote in parameter will disapper. Need escape quote like \"\"
# ただ foo 関数を頭につけてあげたいが、パラメーターの "" が消えてしまうので \"\" でエスケープが必要
# CLIBS is '-L/usr/local/lib -L/lib/x86_64-linux-gnu/'
echo "* echo ..."
make foo CLIBS="$libs"
# 🚀 GOOD.
# make foo CLIBS="-L/usr/local/lib -L/lib/x86_64-linux-gnu/"
# CLIBS is '-L/usr/local/lib -L/lib/x86_64-linux-gnu/'
echo "* run \\ ..."
foo make foo CLIBS=\"$libs\"
# 😢 BAD.
# make foo CLIBS=-L/usr/local/lib -L/lib/x86_64-linux-gnu/
# make: invalid option -- '/'
# Usage: make [options] [target] ...
# foo make foo CLIBS="$libs" # require escape "libs" -> \"$libs\"
# 🤔 SOSO. missing quote from `echo` message.
# make foo CLIBS=-L/usr/local/lib -L/lib/x86_64-linux-gnu/
# CLIBS is '-L/usr/local/lib -L/lib/x86_64-linux-gnu/'
echo "* run ..."
foo2 make foo CLIBS="$libs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment