What command is being misused in this script?

Asked

Viewed 52 times

1

Whenever I run the script, the error message appears saying that the grep was used in the wrong way, which is wrong in the script ?

Code:

#!/bin/bash

read $ALVO
RESULTADO=$(ps -A | grep $ALVO)
$RESULTADO kill -KILL 

Error message:

sublime
Uso: grep [OPÇÃO]... PADRÃO [ARQUIVO]...
Experimente "grep --help" para mais informações.
kill: uso: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... ou kill -l [sigspec]

Note: Here the sublime was a test

1 answer

1

As a variable has not yet been assigned a value ALVO you cannot refer to it with "$". Since the variable is empty when using it with the command grep an error is returned.

#!/bin/bash
read ALVO
RESULTADO=$(ps -A | grep $ALVO)
$RESULTADO kill -KILL 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.