Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm writing a bash script and I would like to do the following:
I have a directory with the following:
file001.jpg
file002.jpg
file003.jpg
Now i want a bash script that can give 'file' back to me.
The command: 'cut -c 1-4' doest work for me, cause i also want the same to work on
otherfile001.jpg
otherfiie002.jpg
otherfile003.jpg
So what i'm looking for is a command that can strip the last 7 characters for me.
I've tried the
( filename=otherfile002.jpg; echo ${filename/%???.jpg})
command, it does work on the shell, but how can i use it in my bash script? I have to use it for mutpiple dirs so i think best way i to use with 'ls' right? But how do I get the result from 'ls' in the filename variable?
I'm kinda new to shell scripting. This is my first own script I'm writing.
Because I'm a newbie to shell scripts. Let say I want the easiest way of doing it, it doesn't have to be best way, as long as it is a good way.
well it depends what your circumstances are, most of these ways will work, but do you have different length extensions? different test in extensions? if you do want to use that example there, then you'd simply replace "filename" in the echo part with the variable name you currently have the string assigned to. if you don't actaully want to echo it, but store it, then you'd do, for example:
I'v tried some things, and for me this works good:
cat_profile= ls -1 *001.jpg | rev | cut -c 8- | rev
the result is get is: otherfile.
just what i wanted
thanks everyone for helping me
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.