0
我使用netcat爲聊天創建sh腳本。 這是代碼:Netcat聊天bash腳本問題
#!/bin/bash
clear
echo
echo "-----------------------"
echo "| handShaker Chat 2.0 |"
echo "-----------------------"
echo
read -p 'Server or Client setUp? (s or c) > ' type
if [ $type == 's' ] || [ $type == 'S' ] || [ $type == 'server' ]
then
read -p 'Port (4321 Default) > ' port
if [ $port -gt 2000 ] && [ $port -lt 6500 ]
then
echo
echo "Started listening on port $port."
echo "Stream (Press ctrl + shift to end session) >"
echo
awk -W interactive '$0="Anonymous: "$0' | nc -l $port > /dev/null
else
echo "handShaker Error > The port $port is not a in the valid range (2000 ... 6500)."
fi
elif [ $type == 'c' ] || [ $type == 'C' ] || [ $type == 'client' ]
then
read -p 'Port (4321 Default) > ' port
if [ $port -gt 2000 ] && [ $port -lt 6500 ]
then
read -p 'Destination IP > ' ip
if [[ $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]
then
echo
echo "Started streaming $ip on port $port."
echo "Stream (Press ctrl + shift to end session) >"
echo
awk -W interactive '$0="Anonymous: "$0' | nc $ip $port > /dev/null
else
echo "handShaker Error > Invalid IP Address."
fi
else
echo "handShaker Error > The port $port is not a in the valid range (2000 ... 6500)."
fi
else
echo "handShaker Error > $type is not a valid keyword."
fi
但我有以下問題:awk的-W參數似乎並不存在,並運行後,客戶端程序實際停止。 我正在使用macOS終端。
有人可以幫助我解決這個錯誤並改善我的腳本嗎?
腳本是否不帶'awk'運行?這似乎是一個不正確的語法使用。你有沒有試過評論它?以及'nc $ ip $ port'的輸出是什麼。你可以用'nc -l $ port>/dev/null'修改沒有'awk'部分的行嗎?我覺得在awk中沒有意義 - – Inian
它沒有awk就可以很好地工作。我評論了這一行,並把nc -l $ port和nc $ ip $ port放在了一起。現在我想使用awk,這樣我就可以得到正確的輸出.... – Cristian
從'nc'命令輸出中'awk'需要什麼輸出? – Inian