相关疑难解决方法(0)

如何获取文件的完整路径?

有没有一种简单的方法可以打印完整的路径file.txt

file.txt = /nfs/an/disks/jj/home/dir/file.txt
Run Code Online (Sandbox Code Playgroud)

<command>

dir> <command> file.txt  
Run Code Online (Sandbox Code Playgroud)

应该打印

/nfs/an/disks/jj/home/dir/file.txt
Run Code Online (Sandbox Code Playgroud)

unix linux file path

669
推荐指数
9
解决办法
86万
查看次数

在bash中提取没有路径和扩展名的文件基名

给定这样的文件名:

/the/path/foo.txt
bar.txt
Run Code Online (Sandbox Code Playgroud)

我希望得到:

foo
bar
Run Code Online (Sandbox Code Playgroud)

为什么这不起作用?

#!/bin/bash

fullfile=$1
fname=$(basename $fullfile)
fbname=${fname%.*}
echo $fbname
Run Code Online (Sandbox Code Playgroud)

什么是正确的方法呢?

unix linux bash filenames

303
推荐指数
6
解决办法
47万
查看次数

标签 统计

linux ×2

unix ×2

bash ×1

file ×1

filenames ×1

path ×1