3 ms·
Mostly agree, but I add more. 1. end all your lines C-style; this may save your life many times; 2. declare -is variables and -r CONSTANTS at the beginning, a
by IYasha 4y ago
Mostly agree, but I add more.
1. end all your lines C-style; this may save your life many times;
2. declare -is variables and -r CONSTANTS at the beginning, again, C-style;
3. print TIMESTAMP="$(date +%Y-%m-%d\ %H:%M:%S)"; where appropriate if your script logs its job;
4. Contrary to OPs reommendation I strongly try to stick to pure SH compatibility in smaller acripts so they can run on routers, TVs, androids and other busybox-like devices; BASH isn't everywhere.
- rethab 4y agohow do you make sure your scripts are SH compatible?
- IYasha 4y agoMake sure? Well, aside from keeping sh feature subset in my head, I usually run them like "sh myscript.sh" on target or limited environment (they have #!/bin/sh shebang) for testing. Other people here probable have better suggestions though. )
- oftenwrong 4y agoI like to use: date -u +%Y-%m-%dT%TZ because the time zone is unambiguous, the command works with POSIX date, and it's valid under both ISO 8601 and RFC 3339.