[英]How can I execute a command anywhere if certain required files are different directories?
假設命令為my_command
並且此命令必須在當前工作目錄中准備特定的文件(file1,file2和file3)。
因為我經常在許多不同的目錄中使用my_command
,所以我想將某些文件保留在某個目錄中,然后在工作目錄中不包含這三個文件的情況下執行my_command
。 我的意思是我不想將這三個文件復制到每個工作目錄中。
例如:
包含三個文件的目錄/home/chest
工作目錄: /home/wd
如果執行命令my_command
,它將自動識別/home/chest/
的三個文件
我認為這種方式類似於添加$ PATH而不是添加可執行文件,而是添加文件。
似乎文件需要位於當前工作目錄中才能使vasp_std
命令按預期工作,我認為您可以將所有文件簡單地添加到主目錄中的include文件夾中,然后從該目錄創建指向該文件夾的符號鏈接您的腳本。 在腳本末尾,符號鏈接將被刪除:
#!/bin/bash
# create a symbolic link to our resource folder
ln -s ~/include src
# execute other commands here
# finally remove the symbolic link from the current directory
unlink src
如果vasp_std
命令要求將文件直接放置在當前工作目錄下,則可以為每個文件創建符號鏈接:
#!/bin/bash
# create link for to all resource files
for file in ~/include/*
do
ln -s $file `basename $file`
done
# execute other commands here
# remove any previously created links
for file in ~/include/*
do
unlink `basename $file`
done
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.