0

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

lutube
  • 35
  • 3
  • See: [How to manually expand a special variable (ex: ~ tilde) in bash](https://stackoverflow.com/q/3963716/3776858) – Cyrus Aug 19 '20 at 19:10
  • See https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html. Your invocation does not match any of the condition which could expand the `~` character to the user's home directory path – Inian Aug 19 '20 at 19:17
  • It's not a problem with relative locations, it's a problem with `~` in particular. `~` _isn't_ a relative path at all, for that matter, as `~` expands to `$HOME`, which is absolute on any reasonable system. – Charles Duffy Aug 19 '20 at 20:14

0 Answers0