0

When I run my script:

#!/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 "";;

I get the error:

current_id: command not found

[: -ne: unary operator expected

I am trying to find the child-parent tree with this method. Is there something wrong with my syntax? Or is the current_id = "$$" not allowed? Thank for your help.

Pr68
  • 9
  • 1

1 Answers1

0

In assignment, there must not be a space before =

current_id =$(...)   # tries to run a program called current_id, which does not exist
current_id=$(...)    # assigns a value to variable
Jokester
  • 5,501
  • 3
  • 31
  • 39
  • That seemed to fix the "current_id: command not found", however the [: -ne: unary operator expected error is still lingering. Thanks for your help. – Pr68 Feb 10 '16 at 02:37
  • @pr68: Try putting an extra set of `[` `]` around your while statement. (eg.`while [[ $current_id -ne 1 ]]`) – l'L'l Feb 10 '16 at 02:40
  • @I'L'I I found the issue my if statement needed to go from ` '(if ( $s == '$current_id' ) print $3;)') ` to `'{ if ( $2 == '$current_id' ) print $3;}')`. Thanks for the help. – Pr68 Feb 10 '16 at 02:45