Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
The problem statement, all variables and given/known data:
This script will analyse the channels.txt e registrations.txt and it will allow to mage the channels and the users registrations on the channels. It should look similar to this:
Channel administration of SlackIUL:
Channels list
Add channel
Remove channel
Associate user to channel
Channel users list
Remove channel user
Exit
Always that justifies, the script should ask o the users name and/or channel name.
channels.txt
Geral
SO
PCD
FBD
registrations.txt
2016-09-26 14:00:01 paulo Geral
2016-09-26 14:01:11 paula SO
2016-09-27 10:33:17 paulo SO
2016-09-27 13:32:10 rita Geral
2016-09-27 13:32:12 rita FBD
I've tried doing it but there is always some syntax error.
Relevant commands, code, scripts, algorithms:
The attempts at a solution (include all code and scripts):
#!/bin/bash
echo "-----------------------------------"
echo "Administration options of SlackIUL"
echo "1. Channels list"
echo "2. Add channel"
echo "3. Remove channel"
echo "4. Associate user to channel"
echo "5. Channel users list"
echo "6. Remove user from channel"
echo "7. Exit"
read x
case $x in
1) cat channels.txt ;;
2) echo "Say the channel to add:"
read channel_add
if [ grep -q $channel_add 'channels.txt' == 0 ]; then
echo "Channel already exists"
else
echo "$channel_add" >> "channels.txt"
fi
3) echo "Say channel to remove:"
read channel_remove
if [ grep -q $channel_remove 'channels.txt' == 0 ]; then
echo "$channel_remove" << "channels.txt"
else
echo "The channel you want to remove, does't exist."
fi
4)
5) echo "Say the channel from wich to list users:"
read channel
if [ cat registrations.txt | grep $channel ]; then
cat registrations.txt | grep $channel | cut -d ' ' -f3
else
echo "The channel doesn't exist!"
fi
6) echo "Say the channel:"
read channel
echo "Say the user to remove:"
read user
if [ cat registrations.txt | grep $user | grep $channel ]; then
line=$(cat -n registrations.txt | grep $user | grep $channel)
echo "$line" << "registrations.txt"
7) echo "Till next time :)" ;;
*) echo "Invalid option"
x=0;;
esac
done
Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
ISCTE, Lisbon, Portugal, Fernando Batista, Licenciatura em Engenharia Inform�tica (9119) [ISTA]
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
In your school data the course number is missing. Please complete.
Please be aware that supplying sample data like channels.txt and registrations.txt usually helps, as does posting the syntax error messages.
On first sight, I see the following:
missing double semicolons on a few of the cases.
<< opens a "here document", the syntax (and logics) for which you do not follow. It seems you would need an output redirection in those places.
grep et al. don't need cat - they usually read the input files by themselves.