0

I'm trying to run a script that installs some files in a directory a user specifies. Once the user specifies the directory, I'd like to transfer the main file to that directory so it can perform so more tasks there before ultimately deleting itself once complete.

    #prompt for directory in which to build project
    read -p "Drag and drop the directory in which you'd like to build this project:  "

    echo "reply is $REPLY"
    cp ./myScript.sh $REPLY
    /bin/bash $REPLY/myScript.sh

I've got the script to execute the file from this question. I tried doing it with source $REPLY/myScript.sh as well as simply sh $REPLY/myScript.sh. I get the error /path/to/file/ is a directory

It must be that it doesn't known I'm trying to run myScript.sh, but I don't understand how I've given it a directory.

Community
  • 1
  • 1
1252748
  • 14,597
  • 32
  • 109
  • 229

2 Answers2

1

A likely cause is that drag-and-drop is putting whitespace after the directory name.

Thus:

/bin/bash $REPLY/myScript.sh

would be running

/bin/bash /path/to/directory /myScript.sh

A simple fix, if that's only a standard space, would be:

/bin/bash "${REPLY% }/myScript.sh"
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • @thomas, it's a parameter expansion that strips the trailing space. See http://wiki.bash-hackers.org/syntax/pe for a full reference, or http://mywiki.wooledge.org/BashFAQ/073 for a gentler introduction. – Charles Duffy May 11 '15 at 16:31
-2

You are missing the variable in read command so obiously it will fail as whatever you are reading is not getting stored. You can replace the read command as follows.

#prompt for directory in which to build project
    read -p "Drag and drop the directory in which you'd like to build this project:  " REPLY
Sriharsha Kalluru
  • 1,743
  • 3
  • 21
  • 27
  • 1
    Untrue. `read` by default stores to the variable `$REPLY`. (This is a bashism rather than POSIX behavior, but then, this is a question tagged for bash). – Charles Duffy May 11 '15 at 16:05