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 a new file

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

My bash script

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

The screen output terminal:

Bash script create new file


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 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. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

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