I’m working on the Relational Database Certification, doing the Periodic Table Database exercise.
I have finished all instances of the exercise except for the following:
" If you run ./element.sh 1
, ./element.sh H
, or ./element.sh Hydrogen
, it should output The element with atomic number 1 is Hydrogen (H). It's a nonmetal, with a mass of 1.008 amu. Hydrogen has a melting point of -259.1 celsius and a boiling point of -252.9 celsius.
"
I get the desired input when I pass a number and a full element name as an argument, but I can not get the symbol (i.e. ‘H’) argument to work.
here are the if statements of my code:
# if word or symbol
if [[ ! $1 =~ ^[0-9]+$ ]]
then
ELEMENT=$($PSQL "SELECT atomic_number, symbol, elements.name, atomic_mass, melting_point_celsius, boiling_point_celsius, types.type FROM properties JOIN elements USING(atomic_number) JOIN types USING(type_id) WHERE elements.name='$1'")
else
ELEMENT=$($PSQL "SELECT atomic_number, symbol, elements.name, atomic_mass, melting_point_celsius, boiling_point_celsius, types.type FROM properties JOIN elements USING(atomic_number) JOIN types USING(type_id) WHERE elements.name='^$1' ORDER BY atomic_number")
fi
# if number
if [[ $1 =~ ^[0-9]+$ ]]
then
ELEMENT=$($PSQL "SELECT atomic_number, symbol, elements.name, atomic_mass, melting_point_celsius, boiling_point_celsius, types.type FROM properties JOIN elements USING(atomic_number) JOIN types USING(type_id) WHERE elements.atomic_number=$1")
fi
LINK TO EXERCISE
I don’t know what condition to put in order for the script to recognize the symbol argument, any ideas are welcome.
Thank you for reading!