得到的文件路径文件目录路径 [英] Get file directory path from filepath

查看:185
本文介绍了得到的文件路径文件目录路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在bash编程如果 VAR =/家/我/ MYDIR / file.c中,结果
如何获得/家/我/ MYDIR

In bash programming If VAR="/home/me/mydir/file.c",
How to get the "/home/me/mydir".

推荐答案

目录名基本名是工具,你是在寻找用于提取路径组件:

dirname and basename are the tools you're looking for for extracting path components:

$ VAR=/home/me/mydir/file.c

$ DIR=$(dirname "${VAR}")

$ echo "${DIR}"
/home/me/mydir

$ basename "${VAR}"
file.c

他们不是的内部庆典命令,但应可在绝大多数系统将运行庆典

They're not internal bash commands but should be available on the vast majority of systems that will be running bash.

这篇关于得到的文件路径文件目录路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆