1. The problem statement, all variables and given/known data:
Write a shell program called myenv which takes one argument. The argument should be the name of an environment variable, such as PATH HOME etc. myenv should print out the value of the variable given as the argument. If no argument is given, or the argument is invalid, your program could do unpredictable things!
e.g., myenv PRINTER
should print a line such as: PRINTER=kc3500
e.g., myenv HOME PRINTER
should print a line such as: HOME=/home/dwoit
2. Relevant commands, code, scripts, algorithms:
None that I can think of? Besides the basic start of #!/bin/bash
3. The attempts at a solution (include all code and scripts):
I'm not sure how to write this... I assume I could try setting the argument to a local variable within the script, but that's the next topic (local variables) so I don't think I have to. I know you can see the values of environment variables by typing in $ and then the one you want, so I tried doing ${"$1"} within the program but it doesn't work (I get a bad substitution error) and I have no idea how else to do it. Any help is appreciated, thanks.
#!/bin/bash
echo ${"$1"}
exit 0
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Ryerson University, Toronto, Canada, Denise Woit,
CPS393