-1
我想在这里做的回声:庆典反引号反引号
if [ $1 ]
then
temp=`sudo fuser $1/tcp 2> /dev/null | tr -s ' ' | cut -d ' ' -f 2`
echo 'The command '`cat /proc/$temp/cmdline`' use the port '$1
else
echo "Give a port number"
fi
在这样一行:
if [ $1 ]
then
echo 'The command '`cat /proc/`sudo fuser $1/tcp 2> /dev/null | tr -s ' ' | cut -d ' ' -f 2`/cmdline`' use the port '$1
else
echo "Give a port number"
fi
但shell解释
`cat /proc/`
为一个命令(这是正常的,我知道它)
我只是想知道如果我能做到这一点在一行中没有一个临时变量
编辑:现在我有这个
#!/bin/bash
RED='\033[0;33m'
NC='\033[0m'
#H
echo -e ${RED}'usePort.sh'${NC}
if [ $1 ]
then
echo "The command $(cat /proc/$(sudo fuser $1/tcp 2> /dev/null | tr -s ' ' | cut -d ' ' -f 2)/cmdline) use the port $1"
else
echo "Give a port number"
fi
输出是这样的: $ ./usePort.sh 22 usePort.sh ./usePort.sh: line 9: warning: command substitution: ignored null byte in input la commande /usr/sbin/sshd-D utilise le port 22
没关系,所以当我使用这个: '回声'命令'$(cat/proc/$(sudo fuser $ 1/tcp 2>/dev/null | tr -s''|在使用端口$ 1' 回声线在解释器中有这样的:'第10行:警告:命令替换:忽略输入中的空字节' – HolyFredy
@HolyFredy它会不工作,这样,由于单引号,使用'echo“命令cat/proc/$ temp/cmdline使用端口$ 1”' –
即使使用'echo“命令$(cat/proc/$(sudo fuser $ 1/tcp 2>/dev/null | tr -s''| cut -d''-f 2)/ cmdline)使用端口$ 1“'我有同样的警告(注意回显提示正确) – HolyFredy