Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Takes No Damage
Nov 20, 2004

The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of infinity, and it was not meant that we should voyage far.


Grimey Drawer
Humble Request
Problem: This is really just Bash shell ignorance on my part, but the nature of my issue makes it difficult to Google.
Description and requirements: I'm trying to set up a script to move some files around based on a string in the filename, trouble is there are characters immediately following the 'search string' bit and I don't know how to call a variable as part of a string without including trailing characters.

Example: I'm trying to key off of a year as part of a datestamp yyyymm i.e. 199810blablabla would be October 1998. So I've got a bunch of files from October 1998 and I want to move them into an October folder inside a 1998 folder. Typing the command manually this would just be:
mv 199810* /1998/October/

But I'm getting tired of doing this 12 times for every year so I want to make a script with a global DATE variable that contains the year, so I can just edit that one bit of the script and run it once for each year, so it would contain something like:

#!/bin/sh
DATE="1998"
mv $DATE10* /$DATE/October/

Of course this fails because I don't know how to separate DATE and 10* without introducing a whitespace. How to do?

Nice to have features:

e:
Of course I only posted this to trick the universe into telling me the answer immediately afterwards, which it did. echo $DATE\blablabla will produce the output 1998blablabla. Didn't know I could 'escape' entire variables :argh:

Takes No Damage fucked around with this message at 22:41 on Mar 30, 2021

Adbot
ADBOT LOVES YOU

Takes No Damage
Nov 20, 2004

The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of infinity, and it was not meant that we should voyage far.


Grimey Drawer
Good to know, the { } method looks a bit cleaner, but putting the entire variable in " " makes sense as well, so I may edit over to one of those just to keep things Best PracticeTM. Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply