Computer scienceSystem administration and DevOpsCommand lineCommand line basics

Parameters and options

Fixing a script to confirm file existence

Report a typo

You have a bash script that is designed to confirm whether a file exists in the current directory. However, it is not functioning correctly because some parts are missing. Your task is to fill the blanks in the code so that the script reads the name of the file as a parameter from the command line, checks if it exists, and prints 'File exists.' if it does, and 'File does not exist.' if it doesn't.

Fill in the gaps with the relevant elements
#!/bin/bash
fileName=$1
 [ -f "$fileName" ];then
   "File exists."

  echo "File does not exist."
fi
echoifelse
___

Create a free account to access the full topic