这应该有用,我只是测试了它并且它按预期工作:没有扩展,替换,或者你发生了什么。cat <<
#!/bin/bash
curr=`cat /sys/class/backlight/intel_backlight/actual_brightness`
if [ $curr -lt 4477 ]; then
curr=$((curr+406));
echo $curr > /sys/class/backlight/intel_backlight/brightness;
fi' > file # use overwrite mode so that you don't keep on appending the same script to that file over and over again, unless that's what you want.
使用以下也有效。cat << file
... code ...'
此外,值得注意的是,当使用heredoc时,例如<< EOF,替换和可变扩展等发生。所以做这样的事情:cat < file
cd "$HOME"echo "$PWD" # echo the current pathEOF
总是会导致变量$HOME和扩展$PWD。因此,如果您的主目录是/home/foobar当前路径/home/foobar/bin,file则如下所示:cd "/home/foobar"echo "/home/foobar/bin"
而不是预期的:cd "$HOME"echo "$PWD"