我的.bashrc中有一个名为groovy的函数。
我有这个bash脚本,我想使用groovy。
它说./batch.sh: line 7: groovy: command not found
虽然我在脚本的开头提供了.bashrc。
我错过了什么?
batch.sh
#!/usr/bin/env bash
source ~/.bashrc
for file in *.html;
do
name="${file%.html}"
groovy "$name.html" "uncached/$name.mp3"
done;
.bashrc的一部分
function groovy {
sed -n '/<pre>/,/<\/pre>/p' "$1" | replace '<pre>' '' '</pre>' '' | hextomp3 - "$2"
}
function hextomp3 {
echo "in $1"
echo "out $2"
echo "cut -c10-74 $1 | xxd -r -p - $2"
cut -c10-74 "$1" | xxd -r -p - "$2"
}
输出:
chaouche@karabeela ~/DOWNLOADS/MUSIQUE $ ./batch.sh
./batch.sh: line 6: groovy: command not found
./batch.sh: line 6: groovy: command not found
./batch.sh: line 6: groovy: command not found
./batch.sh: line 6: groovy: command not found
./batch.sh: line 6: groovy: command not found
./batch.sh: line 6: groovy: command not found
答案 0 :(得分:4)
/etc/bashrc
,~/.bashrc
不。
您可能会看到与
类似的内容case $- in
*i*) ;;
*) return;;
esac
或
[ -z "$PS1" ] && return
在~/.bashrc
。
考虑将您的功能添加到~/.profile
或~/.bash_profile
(如果后者存在)。