我想在 Array 的檔案夾下找到 bash 腳本檔案。但是 bash 腳本檔案沒有指定的擴展名。我寫了這樣的東西:
for i in "${array[@]}"
do
# Here I will write the condition that the file is found in the folder $k
done
uj5u.com熱心網友回復:
如果您的腳本在它們的第一行中有#!/bin/bash或#!/bin/sh(它們應該),那么您可以使用該file命令來檢查檔案是否是腳本。
例如,拿這個腳本:
#!/bin/bash
echo "I am a script!"
file filename.shwill 的輸出filename.sh: Bourne-Again shell script, ASCII text executable,這表明它是一個 shell 腳本。請注意,該file命令不使用檔案的擴展名來指示其格式,而是使用它的內容。
如果您的檔案開頭沒有這些行,您可以嘗試運行每個檔案(命令bash filename.ext:)并通過檢查變數的值來檢查它是否運行成功${?}。這不是一個干凈的方法,但如果您別無選擇,它肯定會有所幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/393516.html
下一篇:`execsh-c`是什么意思
