【问题标题】:How to join paths in shell script [duplicate]如何在shell脚本中加入路径[重复]
【发布时间】:2014-11-24 08:53:26
【问题描述】:

要在我的cwd 在 python 中获取文件,我可以这样做:

import os
cwd = os.getcwd()

filename = 'file.txt'
path = os.path.join(cwd, filename)

我如何在 shell 脚本中做同样的事情?

【问题讨论】:

标签: python bash shell


【解决方案1】:

可以在bash中使用pwd命令获取当前工作目录。
通常,变量$PWD 包含目录。所以应该这样做:

full_path="${PWD}/foo.txt"

并通过调用pwd 命令:

full_path="$(pwd)/foo.txt"

【讨论】:

    猜你喜欢
    • 2011-07-15
    • 1970-01-01
    • 2016-04-26
    • 2013-12-10
    • 1970-01-01
    • 2015-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多