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