如何使用Perl創建另一個名爲hello.sh
的文件?生成bash腳本
我想:
#*perl codes*
#Before this has perl's section of codes
#Now want to create shell script
open FILE , ">hello.sh" or die $!;
chmod 0755, "hello.sh";
print FILE
"#!/bin/sh
echo "Hello World!
";
close FILE;
但是,這是非常多餘。如果我想使用IF-ELSE,那麼這樣做很難。
有什麼想法?
編輯
我想這
print FILE
"#!/bin/sh
if [-d $1]; then
echo "It's a directory at $(pwd)"
else
echo $1 is not a directory
fi
";
正如你所看到的,Its
檢測爲不是字符串, 難道我錯過這裏的任何語法?
Perl可以將任何內容打印到您可以鍵入到af的文件中ile,是的。 –
是的,你可以,沒有什麼困難,你的評論根本沒有意義。 – hobbs
你不打印你的文件內容。這只是一個字符串,不會去任何地方。 – Arkadiy