⇤ ← Revision 1 as of 2014-04-30 12:27:21
1174
Comment:
|
← Revision 2 as of 2014-04-30 22:48:21 ⇥
1150
Fix formatting. The content is still a bit flimsy.
|
Deletions are marked like this. | Additions are marked like this. |
Line 6: | Line 6: |
* cat takes text FROM a file * the only reason to use cat is so that you can use a heredoc and you usually want to use a heredoc if there is much to write * when you need to read stdin and need to write to stdout * when you actually need to conCATenate stuff e.g. you need to write several files in one go, or mix files and stdin |
* cat takes text FROM a file * the only reason to use cat is so that you can use a heredoc and you usually want to use a heredoc if there is much to write * when you need to read stdin and need to write to stdout * when you actually need to conCATenate stuff e.g. you need to write several files in one go, or mix files and stdin |
Line 14: | Line 12: |
* when you're using an old shell without printf * *should* or *can* ? Maybe when you're quite certain of the output - no vars and no backslashes and no leading hyphens - and the brevity over printf matters, then, maybe, you should use echo |
* when you're using an old shell without printf * *should* or *can* ? Maybe when you're quite certain of the output - no vars and no backslashes and no leading hyphens - and the brevity over printf matters, then, maybe, you should use echo |
Line 20: | Line 16: |
* [[http://mywiki.wooledge.org/ParsingLs|NEVER]]: Globs are much more simple AND correct: ''for file in *.txt'' * if you are caught between a rock and a REALLY hard place then ls might be the only choice you have to find out certain information, like where a symlink points. but it's really a last resort and in the vast majority of cases not needed at all |
* [[http://mywiki.wooledge.org/ParsingLs|NEVER]]: Globs are much more simple AND correct: ''for file in *.txt'' * if you are caught between a rock and a REALLY hard place then ls might be the only choice you have to find out certain information, like where a symlink points. but it's really a last resort and in the vast majority of cases not needed at all |
Should I use cat or echo?
cat or echo are used to generate the text that will be written somewhere
When should I use cat?
- cat takes text FROM a file
- the only reason to use cat is so that you can use a heredoc and you usually want to use a heredoc if there is much to write
- when you need to read stdin and need to write to stdout
- when you actually need to conCATenate stuff e.g. you need to write several files in one go, or mix files and stdin
When should I use echo?
- when you're using an old shell without printf
- *should* or *can* ? Maybe when you're quite certain of the output - no vars and no backslashes and no leading hyphens - and the brevity over printf matters, then, maybe, you should use echo
When should I use ls?
NEVER: Globs are much more simple AND correct: for file in *.txt
- if you are caught between a rock and a REALLY hard place then ls might be the only choice you have to find out certain information, like where a symlink points. but it's really a last resort and in the vast majority of cases not needed at all