假设我想将一个文件的路径保存到 Linux 终端中的一个变量中。我可以这样做:
VARIABLE=/home/john/Documents/example.txt
有没有办法用其他程序(例如 Ranger)来做到这一点?在伪代码中:
echo "Choose a file:"
// launch Ranger
// return a file path into a variable
echo $example_variable
// prints the file you chose with Ranger
最佳答案
你可以这样使用:
echo "Choose a file:"
tempfile=$(mktemp)
ranger --choosefile="$tempfile"
read -r example_variable < "$tempfile"
rm -f "$tempfile"
我认为它应该是不言自明的。
关于linux - 如何在 Linux 终端中获取另一个程序的文件路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58763837/