LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-19-2021, 12:22 PM   #1
mike acker
Member
 
Registered: Feb 2014
Location: Michigan
Distribution: Debian 10
Posts: 199

Rep: Reputation: Disabled
help clip file extension in bash


any hints / help will be appreciated!!

I'm working in a bash script

I have a file name (e.g.) message.txt.asc

I need to get the plaintext name: message.txt

For some reason I cant get the parameter expansion to work:

TXTNM="${$1%.asc}"

this should result in name for the plaintext as message.txt

i think I've got it now:

TXTNM="${1%.*}"

but I can't see where I've gone wrong

Last edited by mike acker; 01-19-2021 at 12:35 PM.
 
Old 01-19-2021, 12:32 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
You are very close. Check the syntax again.

Code:
TXTNM="${1%.asc}"
 
2 members found this post helpful.
Old 01-19-2021, 02:55 PM   #3
mike acker
Member
 
Registered: Feb 2014
Location: Michigan
Distribution: Debian 10
Posts: 199

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
You are very close. Check the syntax again.

Code:
TXTNM="${1%.asc}"
thanks; I got it working now!
I always have trouble with the quotes and the $
 
Old 01-21-2021, 12:32 AM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,790

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Keep in mind that $var is short for ${var}
The quotes protect against field splitting and filename generation after expansion.
An exercise:

Code:
var1="two words"
var2="*"
printf "%s\n" "${var1} ${var2}"
printf "%s\n" "${var1}" "${var2}"
See what happens if you remove the quotes.

Last edited by MadeInGermany; 01-21-2021 at 12:36 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Requesting terminal command that (recursively) totals size per file extension and number of files per extension triciasurfer Linux - General 8 08-06-2020 07:08 PM
[SOLVED] How can I open a binary file with the extension .chk or no extension? 55sgu Linux - Newbie 3 06-21-2019 02:59 AM
[SOLVED] kdenlive: "clip is invalid" for EVERY clip SUSESailor Linux - Software 2 08-21-2018 11:57 AM
Linux file extension vs Dos file Extension? manaa Linux - Newbie 6 02-12-2009 04:19 PM
Need to edit AVI movie clip SOUND ONLY and re-save to original movie clip Balarabay1 Linux - Software 1 02-06-2008 01:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration