I thought that bash variable substitution and globbing worked at character resolution, so I was rather surprised to see it acting at the byte level.
Everything in my locale is en_AU.UTF-8
When there is nothing to match and the pattern allows zero-to-many, the replacement occurs at the byte level, as seen by subsequent replacements.
I was surprised recently when I did something like
mv ./* ../somedirectory
and found that files like .gitignore were not moved.
I do most of my work in zsh on OS X, and this surprise bit me in bash on CentOS. I tried bash on OS X and found the same behavior: * does not match dot files. This seems very undesirable to me, but apparently it's the bash default.
When, in my terminal, I type
cat ~/my/+(a|b)/doc
It reads ok from both ~/my/a/doc and ~/my/b/doc, but when I put that command in a bash script:
#!/bin/bash
cat ~/my/'+(a|b)'/doc
I get the error:
cat: ~/my/+(a|b)/doc: No such file or directory
Is it not possible to use extended globbing inside a bash script?
I have A.js, B.js, C.js in a certain directory and I want to write a SINGLE command line in bash shell to rename these files _A, _B, _C. How can I do this?
I tried find -name '*.sh' | xargs -I file mv file basename file .sh but it doesn't work, basename file .sh isn't recognized as a nested command
I want to rename a lot of files on Mac OS X (10.7.2).. I don't have the perl package for the rename command.
My files have names like "T452-102456-0.png" and I want to delete the "-0" part. I know I can do this action by writing my own php-cli script, but I would like to know of an easier and faster solution.
I am trying to get parameter substitution working in my bash script ... I know I have gotten this all wrong ... I am trying to create a script that will rename a PART of a file.
#!/bin/bash
for i in *.hpp; do mv -v "$3 ${$3/$1/$2}" ; done
The error I am getting is:
line 2: $3 ${$3/$1/$2}: bad substitution
I have a folder containing photos coming from different cameras.
I use Imagemagick to convert to resized and renamed photos in another folder.
Something like this:
convert "*.jpg" \
-resize 640 -scene 1 \
"${folder}/${prefix}_%02d.jpg"
The problem is some cameras save photos with "JPG" extension, others with "jpg".
To solve this I used to rename extensions with this:
rename .JPG .jp
I'm new with Linux, sed, and awk but I don't mind challenging myself on new ideas. That being said, I understand the purpose and how to use rename and sed for a common event such as adding a $date or removing a _1234 from all the files.
I have to rename multiple files in directory by removing first 5 characters for each filename.
How can I do this i bash/shell? I'm using Ubuntu 11.10. Thanks.