Reputation: 107
I am trying to write a script that will allow the user to input the path of the directory to which they want to store a file. I have something that looks like this:
#! /bin/bash
echo "Enter the directory path"
read varpath
varfile="Filename"
echo "This is a file" > "$varpath$varfile"
what I want is a file in the directory path the user entered called "Filename" and has the line "This is a file" However, I am getting an error saying that there is not such file or directory. Can someone tell me whats wrong, or if there's an alternate solution to this.
Thanks.
Upvotes: 1
Views: 7062
Reputation: 20496
Proabably you need a /
.
echo "This is a file" > "${varpath}/${varfile}"
You can also echo
the variables to make sure they are correct
Upvotes: 4
Reputation: 51
Few things you might want to handle:
The user input directory has the required folders, if not create them using mkdir -p
command.
The user enters dir path that either ends with / or not. If not, you might want to add it yourself.
Upvotes: 0