fast BASH question when comparing username in a test?
i want to create a variable USER to test what user is running a specific script:
Code:
USER=`whoami` i thought -eq was for numbers and = was for letters, but it would appear im way off base here. Thanks in advance for the help. |
You can probably do what you want with this command:
whoami || echo ---------------------- Steve Stites |
Quote:
|
[ xxx ... ] would invoke a command named "[", [xxx ...] would invoke a command named "[xxx"; the space is important! Also, always quote your variables:
Code:
if [ "$USER" = foo ] ... Code:
case "$USER" in |
so many ways..
Code:
USER=`whoami` Code:
echo "the user is $(whoami)" if you want to do something different dependent on username case would be a better fit than a bunch of elifs Code:
case $(whoami) in |
Quote:
whoami will always exit 'true' so echo will never run |
thank you, it was the spacing and ' vs " that was messing me up. many thanks. once I get the code finished ill publish my work. This is to create a remote access (reverse ssh) script for my wife and daughter to run on their laptops connecting to our personal web server so i can remote into their laptops anytime they need help as long as they have internet access. i should be able to get around just about any basic firewall out there and some not so basic firewalls to for that matter.
thus im using foo for now for everything. including my echo vs the assigning a value to variable PORT. |
again thanks for the help, here is a redacted script for those in need of a reverse ssh connection script:
Code:
#!/bin/bash if you do use this, keep in mind that for every user you need to connect via localhost from the 3rd party server you will need to clear your entry in ~/.ssh/known_hosts or you will get key errors as they will not match. i have no clue of any way around that issue. |
|
This seems simpler
Code:
RHOST=some_URL.com |
Quote:
The reason I'm not using a case statement for this script is I want the remote user to do nothing but run the script. Ill take care of the rest. The less work the remote user has to do the better in this case. :D. |
Quote:
|
i see i was getting the case mixed up with getopts as that too uses a case statement. ty.
|
Quote:
|
Quote:
I didn't invent it Nor was I the only one to mention it e.g. ntubski posted 4min before my reply Anyway, since it is on the wiki should probably fix the exit status at the moment it is ..exit;; really it should be ..exit 1;; so any script executing that Rssh.sh script knows it failed. |
All times are GMT -5. The time now is 12:18 AM. |