Linux echo 換行 All In One
auto-install-npm.sh
#!/bin/sh
# sh/zsh/bash 選擇默認
# echo "🚀 linux shell 定時器" && npm i -g app-node-env
# echo "🚀 linux shell 定時器" && yarn global add app-node-env
# 寫入 logs
echo "🚀 linux shell 定時器" >> ./auto-install-npm.log 2>&1
# echo 換行
# echo -e "\n\n\n"
# echo "\n"
# 安裝 log
# yarn global add app-node-env >> ./auto-install-npm.log 2>&1
# 安裝不需要 log
yarn global add app-node-env
# Linux Bash shell 腳本定時器 All In One
# https://www.cnblogs.com/xgqfrms/p/15384401.html
zsh bug ???
# ❌
➜ ~ sudo ./auto-install-npm.sh >> /var/log/auto-install-npm.log 2>&1
zsh: permission denied: /var/log/auto-install-npm.log
➜ ~ ./auto-install-npm.sh >> /var/log/auto-install-npm.log 2>&1
zsh: permission denied: /var/log/auto-install-npm.log
# ✅ OK
$ ./auto-install-npm.sh >> ./auto-install-npm.log 2>&1
linux 2>&1
cron logs
https://stackoverflow.com/questions/4811738/how-to-log-cron-jobs
# 2>&1, 標准輸出和錯誤輸出二合一
* * * * * ./auto-install-npm.sh >> /var/log/auto-install-npm.log 2>&1
https://stackoverflow.com/questions/818255/in-the-shell-what-does-21-mean
crontab / corn
# 定時器任務test
# 每隔 30 分鍾運行一次,使用 sh 自動安裝 app-node-env
# 30 * * * * sh ./auto-install-npm.sh
30 * * * * /bin/sh ./auto-install-npm.sh
https://www.cnblogs.com/xgqfrms/p/15384401.html
echo \n
換行 & EOF 多行注釋 All In One
#!/bin/bash
# echo \n ❌
# echo "sed test\n"
# echo -e \n ✅
echo -e "sed test\n"
# echo $"雙引號 ❌"
# echo $"sed test\n"
# echo $'單引號 ✅'
echo $'sed test\n'
printf "sed test\nabc xyz\n\n"
printf "sed test\nabc xyz"
# sed test
# abc xyz%
# printf % bug ❓zsh bug
# multi lines comments `<<EOF` & `EOF`
# multi_lines_comments = <<EOF
<<EOF
The \`%\` is not printed by \`printf\`, it's printed by \`zsh\` as part of its command prompt.
Bash uses \`$\` or something more complicated instead, that's why it looks different with bash.
\`printf\` prints the same thing both times, and following that the shell prints it's command prompt.
This command prompt looks different in \`zsh\` than in \`bash/sh\`.
https://stackoverflow.com/questions/8467424/echo-newline-in-bash-prints-literal-n
EOF
# echo "$multi_lines_comments"
refs
Linux echo command All In One
https://www.cnblogs.com/xgqfrms/p/15408568.html
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 發布文章使用:只允許注冊用戶才可以訪問!
原創文章,版權所有©️xgqfrms, 禁止轉載 🈲️,侵權必究⚠️!