1

I am trying to write a script and I want to ls a directory. The path is written in a separate file which I am importing with source. When I execute with

#!/bin/bash

source Settings
echo $PathToLaunchers
echo "Availible launchers"
ls -f --color \$PathToLaunchers

In my Settings file is: PathToLaunchers="~/Games/Minecraft/Launchers"

It says

ls: cannot access $Path: No such file or directory

when it should ls the directory that the value holds. How can I make it ls the directory given by the variable?

4

1 回答 1

4

摆脱\眼前的$PathToLanuchers

它正在转义$导致 bash 不扩展变量的 。

命令应该是

ls -f --color $PathToLaunchers

您还需要从周围删除引号~/Games/Minecraft/Launchers这告诉 bash 您想要一个文字波浪号或者如果您想要主目录用 $HOME 替换它

PathToLaunchers=~/Games/Minecraft/Launchers

或者

PathToLaunchers="$HOME/Games/Minecraft/Launchers"
于 2013-05-07T01:24:50.097 回答