Learn Linux, PostgreSQL, Git, and Bash Scripting – right from the command line (new 300-hour freeCodeCamp Certification)

Salon Appointment Scheduler:

Stuck on this step:
You should display a numbered list of the services you offer before the first prompt for input, each with the format #) <service> . For example, 1) cut , where 1 is the service_id

Code so far is this:

#! /bin/bash
PSQL="psql -X --username=freecodecamp --dbname=salon --tuples-only -c"
#echo -e "\n~~~~~ Salon Appointment Scheduler ~~~~~\n"

MAIN_MENU() {
  #display a numbered list of the services you offer before the first prompt for input, each with the format #) <service>
  #get services
  SERVICES=$($PSQL "SELECT service_id, name FROM services ORDER BY service_id;")
#display services
    #echo -e "\nHow may I help you?"
    echo "$SERVICES" | while read SERVICE_ID BAR SERVICE_NAME
    do
      echo "$SERVICE_ID) $SERVICE_NAME"
    done
  read MAIN_MENU_SELECTION

}

MAIN_MENU

See if you can use ‘sed’ instead of while and read here:

echo “$SERVICES” | sed .....
1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

I also had encountered some difficulties with this test. I think that you can pass it if you uncomment and move the two echo statement on top, above the MAIN_MENU function.

If you need more help or you need a programming buddy just ask :slight_smile:

1 Like

After an hour or so I was able to use 2 sed commands:

 echo "$SERVICES" | sed -E 's/^ *| *$//g' | sed -E 's/ \|/)/g' 

I also moved the echo commands on top (out of the MAIN_MENU)
Here is the output:

1) cut
2) color
3) wash

If someone could help me combine the 2 sed commands into one maybe that would get the :ballot_box_with_check:?

Can you share the output of just this from your program?

echo "$SERVICES"

1 Like

I didn’t use at all the sed command for this project and I used the while-read technique.

I think the problem lies in the formatting: In the second echo statement, MOVE the \n to the end like this:

#echo -e “How may I help you?\n”

1 Like
codeally@1a42115475b8:~/project$ ./salon.sh
1) cut
2) color
3) wash

Yes but also remember to remove the # so these echo statements are not commented anymore.

1 Like

Thanks for all your help everyone! Found a full solution on twitter so have been learning from that.

So far got a different box ticked:
:white_check_mark: Your script should prompt users to enter a service_id , phone number, a name if they aren’t already a customer, and a time. You should use read to read these inputs into variables named SERVICE_ID_SELECTED , CUSTOMER_PHONE , CUSTOMER_NAME , and SERVICE_TIME

That one worked, but still got to get the rest of the bottom quarter. Hopefully all I need is time & focus.

1 Like

I always post my code on Twitter so you may have found my solution. In any case, if you need more help you can DM me.

1 Like

Hi all, cc: @moT01,
I am stuck at this step of the Learn Git by Building an SQL Reference Object course.

Steps followed:

The checker says I have not completed the task. Can someone help?

Thanks,
Venkatesh

Hey Venkatesh,
try this - when you exit first instance of nano after changing pick to r and put into a second nano instance, do not change anything in it just yet and simply run the tests. You’ll pass the test and you will have the next instruction on what exactly to change in the second already active nano instance.

Hey @rajpansuriya40, Thanks for the reply. That doesn’t seem to help.

Is there a way to make a dump and re-run the VS Code and pick it up from where I left?

That’s strange, coz it did work in my case;
just to be sure, in the second nano you are just adding an extra s at the end of commit message so it says and not making any other changes and you did not add an r at the beginning of the line in second nano instance. Finally the first line is . Am I right?
Final first line in your second nano instance should be: feat: add column references

Thanks. Had to restart the course!

1 Like

really grateful for this thread! just started this curriculum beta a few weeks ago and am really enjoying it. i’m on the celestial bodies database currently and am working on learning to save my progress. the instructions say the following:

If you leave your virtual machine, your database will not be saved. You can make a dump of it by entering pg_dump --clean --create --inserts --username=freecodecamp universe > universe.sql in a terminal (not the psql one). Make sure you are in the project folder when entering the command. It will save the commands to rebuild your database to universe.sql . Then, save the file somewhere. You can rebuild it by entering psql -U postgres < universe.sql in a terminal if you enter the command where the .sql file is.

So, I made a new terminal that says “bash” instead of “psql” where I put in the first line of code that the instructions recommended here. Then it says I should save the file somewhere… is that as simple as clicking File > Save As… in Visual Studio Code? because I’ve just tried that, and no dialog box appeared for me to select a location. Said dialog box didn’t appear for me either after I posted the first line of code. Not sure what I should be expecting to see here after I run this code.

Separate question: Is it possible for me to run Docker and Visual Studio Code on another machine and to be able to pick up from where I left off in a tutorial from one machine in another? I’ve installed both software, Git, and other extensions, but was unable to build the Docker image on that machine since it kept saying that the Docker daemon wasn’t running, even though the software was open prior to opening VSC, and I’ve tried restarting both programs, restarting the computer, etc. Thanks for your patience!

1 Like

In bash write:

cp universe.sql /workspaces/rdb-alpha/

This is probably the command you are looking for. Once you do that, you should SEE the file universe.sql in the folder /rdb-alpha
It’s the folder that you probably saved on the desktop and that runs the Docker container.

1 Like

I appreciate the help and explanation! Thank you.

EDIT: one final question (that is not necessarily addressed to the person who helped me, but rather anyone) - for statements in the rubric that say blanket statements like, “you should use the INT data type for at least two columns that are not a primary or foreign key” but don’t say “…in each table” at the end, can I assume that out of all of my tables, at least two columns should fulfill this requirement? Or is this something that should be in all of my tables? I’m likely overthinking, but I’d rather ask this now than have to go back and rework my code. Let me know if it’s the former or latter. Thank you!

1 Like