0
I would like some help to resolve these exercises:
In the Ex4.1.sh script add the option to enter the word and file name directly from the command line this way:
$ ./ex4.1.sh <palavra> <arquivo>
In the Ex4.1.sh script the result of the "grep" command is shown on the screen. Change the script in such a way that this result does not appear on the screen. Write a script that tests whether the value passed as a day, month and year parameter is a valid date.
The script in the case is this one:
#!/bin/bash
# ex4.1.sh - teste de desvio
# Script para verificacao de estrutura de desvio
# localiza uma string em um arquivo
echo -n "Digite a palavra a ser localizada: "
read palavra
echo -n "Qual o arquivo a procurar?: "
read arquivo
if grep $palavra $arquivo
then
echo "$palavra encontrada no arquivo $arquivo"
sleep 5
else
echo "$palavra não encontrada no arquivo $arquivo"
sleep 5
fi
Hello fedorqui colleague I managed to solve this example you gave, the problem is I was making it as a script with the code typed in gedit when it was to type directly in the command prompt of linux, there is the result
$ date -d "holaaa" 2> /dev/null && echo "Correct" || echo "Incorrect"
Incorrect
$ date -d "06 Dec 2017" 2> /dev/null && echo "Correct" || echo "Incorrect"
Wednesday Dec 6 00:00:00 AMT 2017
Correct
Thank you so much for your help.
– Fumero
I am not able to do exercise 3, I am receiving command error messages not found, I did the script like this: #!/bin/bash # Ex4.7.sh - date test # Date check script $ date -d "<holaaa>" && echo "correct" || echo "incorrect" incorrect date: invalid date 'holaaa' $ date -d "<28 Mar 2017>" && echo "correct || echo "incorrect" correct
– Fumero
@Smoke the shape is without
< >
-->date -d"28 Mar 2017"
. But what exactly is your question?– fedorqui
I already set and took the biggest signal and the error that appears is this: . /Ex4.7.sh: line 5: $: command not found & #Xa;incorrect . /Ex4.7.sh: line 6: incorrect: command not found . /Ex4.7.sh: line 7: date:: command not found . /Ex4.7.sh: line 8: $: command not found & #Xa;incorrect . /Ex4.7.sh: line 9: Thu: command not found . /Ex4.7.sh: line 10: correct: command not found
– Fumero
Okay. Note my answer gave broad ideas on how to solve this, you have to put effort alone in the script. Also, better update your question with this code and specific questions about what is failing. Thank you!
– fedorqui