|
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 Takes No Damage fucked around with this message at 22:41 on Mar 30, 2021 |
# ¿ Mar 30, 2021 22:33 |
|
|
# ¿ May 21, 2024 18:07 |
|
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.
|
# ¿ Apr 4, 2021 22:16 |