Conditional branch due to the existence of a shell script file

I want to make a conditional branch depending on the existence of files and directories.

** Combining the -e option with an if statement **

If "If the file already exists, I want to execute it."

#!/bin/bash
filename=hoge

if [ -e $filename];then
  echo "$filename exists"
fi

If you say, "If the file already exists, there is nothing extra to do." ** If you want negative logic, add! Before -e **

#!/bin/bash
filename=hoge

if [ !-e $filename];then
mkdir $filename

that's all

Recommended Posts

Conditional branch due to the existence of a shell script file
Process the contents of the file in order with a shell script
Create a shell script to run the python file multiple times
Template of python script to read the contents of the file
[OCI] Python script to get the IP address of a compute instance in Cloud Shell
How to determine the existence of a selenium element in Python
How to output the output result of the Linux man command to a file
Script to change the description of fasta
I will publish a shell script created to reduce the trouble of creating LiveUSB on Linux
Check the existence of the file with python
[Ubuntu] How to execute a shell script
Script to create a Mac dictionary file
Creating a shell script to write a diary
How to put a line number at the beginning of a CSV file
A shell script to make sure you don't forget the pipenv shell again
I made a program to check the size of a file in Python
The inaccuracy of Tensorflow was due to log (0)
Save the object to a file with pickle
Various ways to read the last line of a csv file in Python
How to pass the execution result of a shell command in a list in Python
Zip-compress any file with the [shell] command to create a file and delete the original file.
Save an array of numpy to a wav file using the wave module
I want to add silence to the beginning of a wav file for 1 second
Python script to get a list of input examples for the AtCoder contest
I made a script to record the active window using win32gui of Python
How to display the modification date of a file in C language up to nanoseconds
A memo to visually understand the axis of pandas.Panel
Let's understand the standard input / output of bash together and write a shell script.
[Ansible] Example of playbook that adds a character string to the first line of the file
A memorandum to run a python script in a bat file
A script that can perform stress tests according to the number of CPU cores
Steps to calculate the likelihood of a normal distribution
Python script to create a JSON file from a CSV file
Script to get the expiration date of the SSL certificate
Output the output result of sklearn.metrics.classification_report as a CSV file
Python Note: The mystery of assigning a variable to a variable
[Note] A shell script that checks the CPU usage of a specific process in a while loop.
I tried to create a Python script to get the value of a cell in Microsoft Excel
A Python script that allows you to check the status of the server from your browser
How to pass the execution result of a shell command in a list in Python (non-blocking version)
[Ubuntu] How to delete the entire contents of a directory
[python] Change the image file name to a serial number
A Python script that saves a clipboard (GTK) image to a file.
How to run a Python program from within a shell script
[Linux] Copy data from Linux to Windows with a shell script
Access the file with a relative path from the execution script.
A shell script that just emails the SQL execution result
I made a function to check the model of DCGAN
Process the files in the folder in order with a shell script
[Note] Import of a file in the parent directory in Python
I'll never forget how to write a shell script, don't forget! !!
How to see the contents of the Jupyter notebook ipynb file
How to find the scaling factor of a biorthogonal wavelet
I wrote a script to combine the divided ts files
[Shell] How to get the remote default branch in Git
A Python script that compares the contents of two directories
Is there a secret to the frequency of pi numbers?
How to connect the contents of a list into a string
Upload a file to Dropbox
Let's try a shell script
Write a script in Shell and Python to notify you in Slack when the process is finished