user2986042
user2986042

Reputation: 1268

Error when running bash script for creating a new directory

I want to know how to find a file path in bash script using shell Script . I have some folders in my system .The folders are SCRIPT,SRC,OUTPUT . My current path is c:/user/Desktop/project . I have a setup.txt file inside OUTPUT folder . I have a script inside c:/user/Desktop/project/SCRIPT folder :

#!/bin/bash
NAME=$1
CODE=$2
#Find c:/user/Desktop/project
SCRIPT_PATH="$(pwd)"
#create a directory inside output folder
mkdir "/OUTPUT/NEW"
#make a copy of setup.txt file with a name of name-code
/bin/cp -p "OUTPUT/setup.txt" "OUTPUT/NEW/$NAME-$CODE.txt"

But this is not working .Is it correct code ? how can I make a folder and copy a file to that folder inside bash script ? How to correct this code ?

Upvotes: 0

Views: 230

Answers (1)

nsilent22
nsilent22

Reputation: 2863

  1. "$(pwd)" gives a working folder, so if you call you script from c:/user/Desktop/project/SCRIPT it will be c:/user/Desktop/project/SCRIPT, but if you call it from c:/ it will be c:/. It doesn't give your script location.
  2. Creating a "/OUTPUT/NEW" folder will create a folder in the "root" directory. Strip leading slash if you want to use current directory or put a dot in front of it.

Upvotes: 1

Related Questions