I am composing a script to process 20 files. All of them located in different directories. I have partial file name.
- In log directory, File1_Date_time.err change to File1__Date_time_orig.err
- cd ../scripts/
- sh File.sh
File1 directory is /data/data1directory/Sample_File1/logs/File1_Data_time.err
File2 directory is /data/data2directory/Sample_File2/logs/File2_Data_time.err
.....
My script looks like this. (runrunrun.sh)
#!/bin/bash
INPUT=$1
mv /data/*/Sample_*/logs/*_Data_time.err /data/*/Sample_*/logs/*_Data_time_orig.err
cp /data/*/Sample_*/scripts/*.sh /data/*/Sample_*/scripts/*_orig.sh
sh /data/*/Sample_*/scripts/*_orig.sh
When running it, I tried.
./runrunrun.sh File1
. runrunrun.sh File1
sh runrunrun.sh File1
mv: cannot move /data/data1directory/Sample_File1/logs/File1_Data_time.err /data/*/Sample_*/logs/*_Data_time_orig.err
: No such file or directory
cp also got similar feedback
Am I doing it correct?
Thanks!
mv
,cp
, etc. aren't passed the wildcards you're writing, if those wildcards have any valid expansions. Instead, they're passed literal filenames created by running those expansions. Thus, since they don't know the literal wildcards used in the input name, they can't possibly map a*
in the input name to a*
in the output name. – Prisciansh foo.sh
is very dangerous, unless you're absolutely certain that that script starts with#!/bin/sh
rather than#!/bin/bash
,#!/bin/ksh
,#!/bin/zsh
, etc; otherwise, it may use the wrong interpreter. – Priscian