hackugyo
6/16/2015 - 3:14 AM

bashの履歴展開が,agに渡したい正規表現の否定先読みと衝突する

bashの履歴展開が,agに渡したい正規表現の否定先読みと衝突する

# Bash history expansion expands "!***" to a command! So you must use ag with regex in a script like this sample.
# For example, $ag "^(?!.*sample).*$" returns "-bash: !.*sample: event not found"
echo "Please pick me"
echo "Please pick only me!"
echo "sample 1"
ag -G *.sh "^(?!.*sample).*$" #=> 3,4
echo "sample 2"
ag -G *.sh "^.*(?!.*sample).*$" #=> (all lines)
echo "sample 3"
ag -G *.sh "only(?!.*sample).+$" #=> 3