1
我用下面的find命令重命名目錄&文件在Linux系統的Perl +在語法
此話正確設置參數:見rename.pl腳本向下跌破
find/-name 'host1' -print0 | xargs -0 /var/tmp/rename.pl 'print "changing $_\n"; s/host1/host_10/g'
爲了設置參數到位主機1名我設置以下
OLD_HOST=host1
例子:
find/-name "$OLD_HOST" -print0 | xargs -0 /var/tmp/rename.pl 'print "changing $_\n"; s/$OLD_HOST/host_10/g'
的問題是,現在設置$ OLD_HOSTS(如S/$ OLD_HOST/host_10/G」)之後
它不與host_10
更換主機1我的問題:如何正確使用$ OLD_HOST在語法中以host_10替換host1?
#
rename.pl腳本:
#!/usr/bin/perl
#
# rename script examples from lwall:
# rename 's/\.orig$//' *.orig
# rename 'y/A-Z/a-z/ unless /^Make/' *
# rename '$_ .= ".bad"' *.f
# rename 'print "$_: "; s/foo/bar/ if <stdin> =~ /^y/i' *
$op = shift;
for (@ARGV) {
$was = $_;
eval $op;
die [email protected] if [email protected];
rename($was,$_) unless $was eq $_;
}