linux: a shell parameter substitution issue

20 views
Skip to first unread message

ping

unread,
Jul 11, 2012, 4:55:05 PM7/11/12
to linuxus...@googlegroups.com
experts:

I'm trying following Parameter Expansion but somehow it just does't work
-- I do remember previously something like that works fine!

ping@640g-laptop:/data/backup/Juniper/MX/RLI$ ls RLI-12720*
RLI-12720 RLI-12720.html RLI-12720-slides.html RLI-12720-slides.txt
RLI-12720-slides.txt~ RLI-12720.txt RLI-12720.txt~ RLI-12720.xml


ping@640g-laptop:/data/backup/Juniper/MX/RLI$ ls "${RLI-12720.txt%.*}"
ls: cannot access 12720.txt%.txt: No such file or directory

my intention here is to remove the ".txt" suffix so I got filename
RLI-12720 and then ls it, am I missing anything?


thanks!

regards
ping

Jeremiah Bess

unread,
Jul 11, 2012, 6:33:29 PM7/11/12
to linuxus...@googlegroups.com

If all you are trying to do is ls a list of files with the same prefix and extension, just do ls RLI-12720.txt*, like you did in your first example. I'm not clear as to what else you are trying to accomplish.

Jeremiah Bess
Penguin Geek, Network Ninja, Father of Five

--
You received this message because you are subscribed to the Linux Users Group.
To post a message, send email to linuxusersgroup@googlegroups.com
To unsubscribe, send email to linuxusersgroup+unsubscribe@googlegroups.com
For more options, visit our group at http://groups.google.com/group/linuxusersgroup
References can be found at: http://goo.gl/anqri
Please remember to abide by our list rules (http://tinyurl.com/LUG-Rules or http://cdn.fsdev.net/List-Rules.pdf)

ping

unread,
Jul 11, 2012, 6:52:00 PM7/11/12
to linuxus...@googlegroups.com, Jeremiah Bess
On 7/11/2012 6:33 PM, Jeremiah Bess wrote:
> If all you are trying to do is ls a list of files with the same prefix
> and extension, just do ls RLI-12720.txt*, like you did in your first
> example. I'm not clear as to what else you are trying to accomplish.
>

not that easy, actually.
I'm working in vim and is trying to define a ex command to process the
current file based on the filename.

say I'm editing a file named RLI-12720.txt in vim
after some change I want to :
1) save it
2) convert it into html, so I'll get a new file: RLI-12720.html
3) upload (cp) that .html file into web server and test it within browser

so this is the one liner:
:w|!asciidoc -a toc -a toclevels=6 % > /dev/null 2>&1;cp RLI-12720.html
/mnt/public_html/temp/

this works fine, but I want to generalize and save it to make it useful
for all other files, regardless of the filename.

in case you don't use vim, % here means the current filename:
RLI-12720.txt in this case. so what I want to achieve is:

based on current filename "%", generate new filename that will be used
in subsequent command, in this case cp NEW-FILE-NAME ...

thanks



> Jeremiah Bess
> Penguin Geek, Network Ninja, Father of Five
>
> On Jul 11, 2012 4:55 PM, "ping" <songpi...@gmail.com
> <mailto:songpi...@gmail.com>> wrote:
>
> experts:
>
> I'm trying following Parameter Expansion but somehow it just does't
> work -- I do remember previously something like that works fine!
>
> ping@640g-laptop:/data/backup/__Juniper/MX/RLI$ ls RLI-12720*
> RLI-12720 RLI-12720.html RLI-12720-slides.html
> RLI-12720-slides.txt RLI-12720-slides.txt~ RLI-12720.txt
> RLI-12720.txt~ RLI-12720.xml
>
>
> ping@640g-laptop:/data/backup/__Juniper/MX/RLI$ ls "${RLI-12720.txt%.*}"
Reply all
Reply to author
Forward
0 new messages