创建 Bash 函数,将其回显到文件中(语法?)

Create Bash function which echo's into a file (syntax?)

bashrc 中以下函数的正确语法是什么,它会将数字回显到文件中?

我试过:

brightness(){
    "echo '' > /sys/class/backlight/intel_backlight/brightness"
}

我尝试了很多变体,但在这个例子中调用函数时,我得到:

brightness:1: no such file or directory: echo '250' > /sys/class/backlight/intel_backlight/brightness

引号放错了。应该是:

brightness(){
    echo "" > /sys/class/backlight/intel_backlight/brightness
}

顺便说一句,因为文件只能由 root 写入,你需要使用 sudo(除非你 root ). tee 在这里派上用场:

brightness(){
    echo "" | sudo tee /sys/class/backlight/intel_backlight/brightness > /dev/null
}