G
G
gylah-u2022-02-01 00:21:12
bash
gylah-u, 2022-02-01 00:21:12

I can not understand what is the problem in the bash script?

There is a script

#/bin/bash
replace='\033[9m[-] $2\033[0m'
dir='~/todo.txt/'
commands=('add' 'done' 'remove' 'init' 'help')
if [$1 = commands[0][; then
echo '[-] $2' >> dir && cat dir
elif [$1 = commands[1]]; then
sed -i 's/[-] $2/$replace/' dir && cat dir
elif [$1 = commands[2]]; then
sed '/[-] $2/d' dir
elif ["$1" = commands[3]]; then
touch dir
else
echo "Bad arguments. Type todo help to check arguments list."
fi


I can't figure out what's going on and why it's not working. I started learning bash scripts an hour ago.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey, 2022-02-09
@gylah-u

It seems to me that you, my friend, are a noble troll ....

S
Saboteur, 2022-02-01
@saboteur_kiev

This is a cap.
If you started learning scripts an hour ago, learn to write individual commands syntactically correctly, and not take a non-working piece of text from somewhere and not understand what's going on.
To get started, paste your script here and check the syntax of each line
https://www.shellcheck.net/
check which way the quotes are facing, whether you put the spaces correctly.
And in general, it’s easier to write to start

A
AVKor, 2022-02-01
@AVKor

I can not understand what is the problem in the bash script?

This is not a problem, but in general horror is complete.
I can't figure out what's going on and why it's not working.

And it shouldn't work.
I started learning bash scripts an hour ago.

Should have started with "Hello World".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question