avatar
j*n
1
Hi, Every High Hand,
One question
In my shell script, I need to pass a absolute file name to
it:
e.g.
>main.sh /home/username/config.cfg
I need to run this script with different cfg files, and make
some temp directories, according to the filename.
How can I parse the absolute file location to the filename
without extenstion?
e.g.
How to parse '/home/username/config.cfg' -> 'config'?
Thanks in advance.
avatar
m*n
2
#!/bin/ksh
fullpath=/home/username/config.cfg
filename=${fullpath##*/}
echo $filename
withoutext=${filename%.cfg}
echo $withoutext

【在 j***n 的大作中提到】
: Hi, Every High Hand,
: One question
: In my shell script, I need to pass a absolute file name to
: it:
: e.g.
: >main.sh /home/username/config.cfg
: I need to run this script with different cfg files, and make
: some temp directories, according to the filename.
: How can I parse the absolute file location to the filename
: without extenstion?

avatar
c*g
3
#!/bin/csh
set fullpath = /home/username/config.cfg
echo $fullpath齱
set in1 = $fullpath:r
set filename = $in1:r
echo $filename
exit


【在 m******n 的大作中提到】
: #!/bin/ksh
: fullpath=/home/username/config.cfg
: filename=${fullpath##*/}
: echo $filename
: withoutext=${filename%.cfg}
: echo $withoutext

avatar
j*n
4
Thanks, guys, here is another solution
#!/bin/ksh
namein=$1
basein=`basename ${namein}` #the baseline command will
remove the path
nameout=${basein%.cfg}
echo $nameout
It is really cool to have so may High-hands here.

【在 c**g 的大作中提到】
: #!/bin/csh
: set fullpath = /home/username/config.cfg
: echo $fullpath齱
: set in1 = $fullpath:r
: set filename = $in1:r
: echo $filename
: exit
:

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。