shell编程题

1.输入一个域名或IP检查域名或IP是否能访问

#!/bin/bash
#input a area or a IP
read -p "input a network:" ip
#ping ip
ping  -c 3 -W 1 $ip &> /dev/null  
#-c 3 count for ping
#-W 1 time out = 1s
#&> /dev/null remove the display of ping

#check ping
if [ $? -eq 0 ]
then
    echo "the network is ok!"
else
    echo "something wrong!"
fi

 2.I am oldboy linux,welcome to our training.显示这串字符中单词字符数大于6的单词

#!/bin/bash

# replace commas and periods with spaces
text=$(echo "I am oldboy linux,welcome to our training." | tr ',.' ' ')

# Iterate through each word in the processed text
for word in $text
do
    # Check if the length of the current word is greater than 6
    if [ ${#word} -gt 6 ]
    then
        # Print the word if its length is greater than 6
        echo $word
    fi
done

你可能感兴趣的:(spring,java,后端)