Giving relative address as an input to read in bash scripts

46 views Asked by At

I'm a beginner in bash scripting, Sorry if my question is a little bit like a noob. I wrote a scripts to create a configuration and save it to the directory which is taken from the user. the problem is that the scripts is not working when I enter the path of the directory as a relative path, but it is working when I enter the absolute path.

for example: for something like this if I run the following scripts like :

#!/usr/bin/env bash

read -p "Enter the location: " LOCATION
echo "HELLO" > $LOCATION/test1.txt
Enter the location: /home/lutube/Documents

it is working fine. but when I write the relative path like:

Enter the location: ~/Documents
bash: ~/Documents/test1.txt: No such file or directory 

I really appreciate If you help me to solve this problem in a shortest way because my script is already long!! and I also want the reason of the problem.

here the link for eval command: https://i.stack.imgur.com/6ek5U.jpg

0

There are 0 answers