Shell脚本" current_id:命令未找到"错误

时间:2016-02-10 02:27:28

标签: bash sh

当我运行我的脚本时:

#!/usr/bin/env bash

read NUM

case $NUM in
    1)
        current_id = "$$"
        ps -ef > file1.txt

        echo "$current_id"
        while [ $current_id -ne 1 ]
        do 
            current_id =$( cat file1.txt | awk '(if ( $s == '$current_id' ) print $3;)')
            echo " | "
            echo " v "
            echo $current_id
        done

        echo "";;

我收到错误:

current_id: command not found

[: -ne: unary operator expected

我正在尝试使用此方法查找子父树。我的语法有问题吗?或者是current_id =" $$"不允许?谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

在作业中,=

之前不得有空格
current_id =$(...)   # tries to run a program called current_id, which does not exist
current_id=$(...)    # assigns a value to variable