Bash script create new file

In this tutorial, I use a bash script to create a new file. Trick and tips create folder and file with arguments in the bash script. Bash script the essential for DevOps Roles.

Bash script create new file

If “no such folder” then create folder and file.

My bash script

#!/bin/bash
function create-touch() {
  local FILE
  local FOLDER
  FILE=${@:$#}
  FOLDER="$(dirname "$FILE")"
  mkdir -p "$FOLDER" && \touch "$@"
}
create-touch $1 # Call Function in bash script

The screen output terminal:

Bash script create new file

Conclusion

Thought the article, you can use a Bash script to create a new file as above. I hope will this your helpful. More details refer to Bash script.

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.