sh - Bourne Shell Script -


I am trying to write a script in the Born Shell that will do the following:

  1. Read in file name
  2. If the file is not present in the target directory, it will send the message to the user
  3. If the file exists in the target directory, move it to a / garbage folder
  4. If the file exists in the target directory, but a file with the same name / Garbage folder, then it will still move the file to the Trash / directory, but the file will have an _bak extention attached.

    My use of Born Shell is low, so even if I have any indication or suggestion too much will be appreciated, thanks! #! / Bin / sh # script name: garbage utility source_dir = ~ / p6_tmp target_dir = ~ / trash echo "Please enter the filename you want to trash:" Please read the file name if [-f $ Source_dir $ filename] So MV "$ filename" "$ target_dir" else "$ filename does not exist", EF "<">

    < P> You can not use $ to refer to the $ HOME script in sh . Switch to $ HOME (or change Shebang to a shell that supports it, such as #! / Bin / bash ).

    Include one file in a directory, with a slash:

      If [-f "$ source_dir / $ filename"]   

    Before entering the required place, note the ] token.

    To actually move the file that you have tested, use the same expression as the mv for source code:

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -