Register
It is currently Thu Oct 23, 2014 10:28 am

Echo Current User


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Tue Mar 25, 2008 11:42 am   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
Hey everyone. I've written a bash script front end for nmap and I'm quite pleased with it so far. However, there is one function that I can't seem to get. When you first run the script I want it to say "Hello, [currently logged in user], Please specify your scan type:" I've tried using the whoami command to get the currently logged in user, but I can't figure out how to display it properly in syntax. Can I run the command without echoing the results and then save the results as a $variable? Any help would be greatly appreciated.

Thanks,

DeX


Top
 Profile  
 PostPosted: Tue Mar 25, 2008 11:51 am   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
just to give the snippet that I'm working on...here's my attempt using command substitution...it doesn't work though.

Code:
clear;
a=whoami
echo "Hello " $a", Please specify your scan type: "


Top
 Profile  
 PostPosted: Tue Mar 25, 2008 12:03 pm   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
Okay...I figured it out. I feel kinda silly now. Here's what I used...DUH!:

Code:
clear;
echo "Hello "$(whoami)", Please specify your scan type: "


Top
 Profile  
 PostPosted: Tue Mar 25, 2008 12:57 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
you could also use:
Code:
USER=`whoami`
echo "Hello $USER, Please specify your scan type: "


I'm really not sure if there is a difference in using $() versus the backticks... I'm just used to using backticks ``

especially when assigning to a variable so I can use it over and over again :)

o ya... welcome to bashscripts.org :D


Top
 Profile  
 PostPosted: Wed Mar 26, 2008 4:12 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
jbsnake wrote:
I'm really not sure if there is a difference in using $() versus the backticks... I'm just used to using backticks ``


$() is much easier to read without misinterpreting, however backticks do the same thing.

I note also that it's generally the case the environment variable $USER is normally available and contains the current username.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP