如何在Linux终端中使用另一个程序获取文件路径?

问题描述 投票:0回答:1

假设我想在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
linux bash file terminal path
1个回答
0
投票

您可以使用类似这样的内容:

echo "Choose a file:"
tempfile=$(mktemp)
ranger --choosefile="$tempfile"
read -r example_variable < "$tempfile"
rm -f "$tempfile"

我认为这应该是自我解释。

© www.soinside.com 2019 - 2024. All rights reserved.