No, it is not ok. All commands in a pipeline execute at the same time, and the shell prepares redirections before executing the commands. So, it is likely that the command will overwrite the file before cat reads it.
You need sponge(1) from moreutils.
More Related Contents:
- When should I wrap quotes around a shell variable?
- What’s the magic of “-” (a dash) in command-line parameters?
- Aborting a shell script if any command returns a non-zero value
- What does $@ mean in a shell script?
- Better way to rename files based on multiple patterns
- Forcing bash to expand variables in a string loaded from a file
- Linux: copy and create destination dir if it does not exist
- What is the difference between using `sh` and `source`?
- Setting environment variables in Linux using Bash
- What is the difference between “#!/usr/bin/env bash” and “#!/usr/bin/bash”?
- Does “argument list too long” restriction apply to shell builtins?
- Given two directory trees, how can I find out which files differ by content? [closed]
- How to sort a file in-place?
- How to run a shell script on a Unix console or Mac terminal?
- Using the passwd command from within a shell script
- Example of using named pipes in Linux shell (Bash)
- When to wrap quotes around a shell variable?
- How do you normalize a file path in Bash?
- Linux/Unix command to determine if process is running?
- Running shell script in parallel
- Difference between shell and environment variables
- What’s the point of eval/bash -c as opposed to just evaluating a variable?
- Why doesn’t “sort file1 > file1” work?
- Need to remove the count from the output when using “uniq -c” command
- How do you run a script on login in *nix?
- Why should eval be avoided in Bash, and what should I use instead?
- ./configure : /bin/sh^M : bad interpreter [duplicate]
- What does “&” at the end of a linux command mean?
- How to get file creation date/time in Bash/Debian?
- How to convert hex to ASCII characters in the Linux shell?