Create text file and fill it using bash

前端 未结 5 694
一整个雨季
一整个雨季 2020-12-12 19:45

I need to create a text file (unless it already exists) and write a new line to the file all using bash.

I\'m sure it\'s simple, but could anyone explain this to me?

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-12 19:56

    #!/bin/bash
    file_location=/home/test/$1.json
    if [ -e $policy ]; then
      echo "File $1.json already exists!"
    else
      cat > $file_location <

    This code checks if the given JSON file of the user is present in test home directory or not. If it's not present it will create it with the content. You can modify the file location and content according to your needs.

提交回复
热议问题