DEV Community

loading...

Discussion on: Bash random password generator

Collapse
moopet profile image
Ben Sinclair
# Check if the log file is present and if not, create it
if [[ !log_file ]]; then
  touch ~/pass_log.txt
fi
Enter fullscreen mode Exit fullscreen mode

You don't need to create a file in order to append to it - you can use >>| instead of >> later on and it will work.

Collapse
alexgeorgiev17 profile image
Alex Georgiev Author

Hey,

That is indeed correct. It also saves code as well!

Collapse
moopet profile image
Ben Sinclair • Edited

Looks like I'm mixed up.

">>|" will force it on zsh. You don't need that (and it won't be recognised) on bash. Equally, you don't need to create a file on bash prior to writing to it.

I'm mixed up because I regularly use >| to force overwriting a file when I've got noclobber set...

Collapse
alexgeorgiev17 profile image
Alex Georgiev Author

Hey,

That is correct! Thanks for sharing it.