简体   繁体   中英

Bash Script execute command with argument

I am trying to build a new hosting server and migrate over 50+ sites. I need to run this command to build each site using RT Easy Engine.

sudo ee domain.com --php

I have created a txt file with the domains and I can get it to loop through no problem.

array=()
# Read the file in parameter and fill the array named "array"

getArray() {
    i=0
    while read line # Read a line
    do
        array[i]=$line # Put it into the array
        i=$(($i + 1))
    done < $1
}

getArray "domains.txt"

for e in "${array[@]}"
do
    echo $e

done

I change the for loop to

echo "sudo ee " $e

Works OK. get sudo ee domain.com

How do I add the --php on the end and execute?

everytime I add it, I get

--phpe domain.com

You could just try this:

sed 's/\r//g' domains.txt | while read domain; do
    sudo ee "$domain" --php
done

This will read every line and store it in a variable domain , which you can call however you like.

Edit: It may be useful to execute sudo -i first if your root permission runs out during execution (don't know how long the command runs).

Edit2: Added carriage return removal per request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM