Skip to main content
Format, wording, code. Almost everything. Don't worry it is still the same content as the original :-).
Source Link

SH A shell script with anda for loop and an "array"

How can I use this sh script with for loop and an "array" I.
I would like to call the domains with a for infor loop inside the ifif.

fx Example:

for domain in $DOMAINS
do
  printf '%s\n' "$domain"
done
for domain in $DOMAINS
do
  printf '%s\n' "$domain"
done

So if you add that under if then the printfprintf should be like what? forFor example, the wlstopwlstop I would like to be called where the printfprintf is with wls wlstop $domainwls wlstop $domain.

#!/usr/bin/sh

ENV=$1
DOMAINS="1 2 3"

wls (){
echo "$0 : $1 -v -d $2" 
$1 -v -d $2
}

remove (){
echo "$0 : Removing /domains/$1/servers/*" 
set -x
rm -rf /domains/$1/servers/*
set +x
}

echo "$0 : Running wlsfullclean for $ENV"

if [ "$ENV" = "Utv" ]; then

#Stop domain
wls wlsstop 1   
wls wlsstop 2
wls wlsstop 3

#Remove content in servers folder
remove 1
remove 2
remove 3

#wlsclean
wls wlsclean 1
wls wlsclean 2
wls wlsclean 3

#wlscfi
wls wlscfi 1
wls wlscfi 2
wls wlscfi 3

#Start server
wls wlsstart 1
wls wlsstart 2
wls wlsstart 3

elif [ "$ENVI" = "Prod" ]; then
echo "Prod"
fi
#!/usr/bin/sh

ENV=$1
DOMAINS="1 2 3"

wls (){
    echo "$0 : $1 -v -d $2" 
    $1 -v -d $2
}

remove (){
    echo "$0 : Removing /domains/$1/servers/*" 
    set -x
    rm -rf /domains/$1/servers/*
    set +x
}

echo "$0 : Running wlsfullclean for $ENV"

if [ "$ENV" = "Utv" ]; then

    #Stop domain
    wls wlsstop 1   
    wls wlsstop 2
    wls wlsstop 3

    #Remove content in servers folder
    remove 1
    remove 2
    remove 3

    #wlsclean
    wls wlsclean 1
    wls wlsclean 2
    wls wlsclean 3

    #wlscfi
    wls wlscfi 1
    wls wlscfi 2
    wls wlscfi 3

    #Start server
    wls wlsstart 1
    wls wlsstart 2
    wls wlsstart 3

elif [ "$ENVI" = "Prod" ]; then
    echo "Prod"
fi

SH script with and for loop and an "array"

How can I use this sh script with for loop and "array" I would like to call the domains with a for in the if.

fx

for domain in $DOMAINS
do
  printf '%s\n' "$domain"
done

So if you add that under if then the printf should be like what? for example the wlstop I would like to be called where the printf is with wls wlstop $domain

#!/usr/bin/sh

ENV=$1
DOMAINS="1 2 3"

wls (){
echo "$0 : $1 -v -d $2" 
$1 -v -d $2
}

remove (){
echo "$0 : Removing /domains/$1/servers/*" 
set -x
rm -rf /domains/$1/servers/*
set +x
}

echo "$0 : Running wlsfullclean for $ENV"

if [ "$ENV" = "Utv" ]; then

#Stop domain
wls wlsstop 1   
wls wlsstop 2
wls wlsstop 3

#Remove content in servers folder
remove 1
remove 2
remove 3

#wlsclean
wls wlsclean 1
wls wlsclean 2
wls wlsclean 3

#wlscfi
wls wlscfi 1
wls wlscfi 2
wls wlscfi 3

#Start server
wls wlsstart 1
wls wlsstart 2
wls wlsstart 3

elif [ "$ENVI" = "Prod" ]; then
echo "Prod"
fi

A shell script with a for loop and an "array"

How can I use this sh script with for loop and an "array".
I would like to call the domains with a for loop inside the if. Example:

for domain in $DOMAINS
do
  printf '%s\n' "$domain"
done

So if you add that under if then the printf should be like what? For example, the wlstop I would like to be called where the printf is with wls wlstop $domain.

#!/usr/bin/sh

ENV=$1
DOMAINS="1 2 3"

wls (){
    echo "$0 : $1 -v -d $2" 
    $1 -v -d $2
}

remove (){
    echo "$0 : Removing /domains/$1/servers/*" 
    set -x
    rm -rf /domains/$1/servers/*
    set +x
}

echo "$0 : Running wlsfullclean for $ENV"

if [ "$ENV" = "Utv" ]; then

    #Stop domain
    wls wlsstop 1   
    wls wlsstop 2
    wls wlsstop 3

    #Remove content in servers folder
    remove 1
    remove 2
    remove 3

    #wlsclean
    wls wlsclean 1
    wls wlsclean 2
    wls wlsclean 3

    #wlscfi
    wls wlscfi 1
    wls wlscfi 2
    wls wlscfi 3

    #Start server
    wls wlsstart 1
    wls wlsstart 2
    wls wlsstart 3

elif [ "$ENVI" = "Prod" ]; then
    echo "Prod"
fi
Source Link

SH script with and for loop and an "array"

How can I use this sh script with for loop and "array" I would like to call the domains with a for in the if.

fx

for domain in $DOMAINS
do
  printf '%s\n' "$domain"
done

So if you add that under if then the printf should be like what? for example the wlstop I would like to be called where the printf is with wls wlstop $domain

#!/usr/bin/sh

ENV=$1
DOMAINS="1 2 3"

wls (){
echo "$0 : $1 -v -d $2" 
$1 -v -d $2
}

remove (){
echo "$0 : Removing /domains/$1/servers/*" 
set -x
rm -rf /domains/$1/servers/*
set +x
}

echo "$0 : Running wlsfullclean for $ENV"

if [ "$ENV" = "Utv" ]; then

#Stop domain
wls wlsstop 1   
wls wlsstop 2
wls wlsstop 3

#Remove content in servers folder
remove 1
remove 2
remove 3

#wlsclean
wls wlsclean 1
wls wlsclean 2
wls wlsclean 3

#wlscfi
wls wlscfi 1
wls wlscfi 2
wls wlscfi 3

#Start server
wls wlsstart 1
wls wlsstart 2
wls wlsstart 3

elif [ "$ENVI" = "Prod" ]; then
echo "Prod"
fi