linux - 如何在 Linux 终端中获取另一个程序的文件路径?

标签 linux bash file terminal path

假设我想将一个文件的路径保存到 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/

相关文章:

bash - Dockerfile:如何用 build-arg 替换环境变量中的占位符?

bash - 使用 perl 就地替换将软链接(soft link)/符号链接(symbolic link)更改为静态文件

c++ - 无法使用 Fout 创建和命名具有用户输入名称的文件

linux - bash 脚本仅搜索目录特定文件类型

c - 我需要实现一种方法让这个线程休眠直到它有工作要做

bash - 自动完成提升程序选项

c - 如何扫描文本文件的字数和字数?

centOS 上的 Python netadd 模块

linux - Centos安装Git 1.8.5以上版本

c - 从C文件中读取移动数据(字符串和数字)