$(ls etc/nginx/locations/*.locations)
вместо "$file"
для awk сработает, сейчас проверю) for entry in $file
do
awk -i inplace '/location \/projects\/'"$location"'/,/}/ {if(/proxy_pass/) sub(/:[0-9]+.;/,":'"$port"';")} {print}' "$entry"
done
./replace_location_port.sh -n test -v v2.2.2 -p 2222 -f etc/nginx/locations/\*.locations
ls etc/nginx/locations/test.*.locations
Only one integer 0-255 can be returned. Use stdout for other data.
See SC2151.
Попробуйте
location /projects/test/v2.2.2
isPathExists=$(sed -n 's/.*\(location '"$pathWithShieldingSlash"'.*\).*{/\1/p' "$locations_folder/$file_name")
echo "$isPathExists"
while getopts n:v:a:p:sd:mt flag
do
case "${flag}" in
n) name=${OPTARG};;
v) version=${OPTARG};;
a) address=${OPTARG};;
p) port=${OPTARG};;
s) socket=true;;
m) modsecurity=true;;
d) domain=${OPTARG};;
t) test=true
esac
done
locations_folder="/etc/nginx/locations"
path="/projects/$name/$version"
socketPath="$path/socket.io/"
file_name="$domain.$name.locations"
location=""
if [[ $test ]]; then
locations_folder="./etc/nginx/locations"
fi
writeLocation () { printf "\n$location\n" >> "$locations_folder/$file_name"; }
checkLocationExists () {
pathWithShieldingSlash=$(echo "$1" | sed 's/\//\\\//g')
isPathExists=$(sed -n 's/.*\(location '"$pathWithShieldingSlash"'.*\).*{/\1/p' "$locations_folder/$file_name")
echo "$isPathExists"
# if [[ -z $isPathExists ]]; then
# return 0
# else
# return 1
# fi
return [[ -z $isPathExists ]]
}
test=$(checkLocationExists "$path")
if checkLocationExists "$path"; then
echo "FOUND"
else
echo "NOT FOUND"
fi
line 45: return: [[: numeric argument required
location /projects/test/v2.2.2/socket.io/
location /projects/test/v2.2.2
location /projects/test/v2.2.2/socket.io/
location /projects/test/v2.2.2
line 45: return: [[: numeric argument required
NOT FOUND
checkLocationExists () {
pathWithShieldingSlash=$(echo "$1" | sed 's/\//\\\//g')
isPathExists=$(sed -n 's/.*\(location '"$pathWithShieldingSlash"'.*\).*{/\1/p' "$locations_path/$file_name")
echo "$isPathExists"
if [[ -z $isPathExists ]]; then
return 0
else
return 1
fi
}
test=$(checkLocationExists "$path")
if checkLocationExists "$path"; then
echo "FOUND"
else
echo "NOT FOUND"
fi
location /projects/test/v2.2.2/socket.io/
location /projects/test/v2.2.2
location /projects/test/v2.2.2/socket.io/
location /projects/test/v2.2.2
NOT FOUND