Solved

basic bash scripting help with line evaluation

Posted on 2013-01-15
4
552 Views
Last Modified: 2013-01-15
Hi there,

I have this script

#! /bin/bash

USER=whoami

mkdir ~/Desktop/HomeDrive
mkdir ~/Desktop/Shared

WDRIVE=`dscl /Active\\ Directory/THOMASNETDOM/All\\ Domains/ -read /users/$USER | grep SMBHome: | cut -c 10- | tr '\\' '/'`
SINFO=//Server.domain.com/Shared

echo $WDRIVE
mount_smbfs $WDRIVE ~/Desktop/HomeDrive
mount_smbfs $SINFO ~/Desktop/Shared

Open in new window


Which is a login script to mount some .. mounts. I have the problem on the line starting with "WDRIVE=`dscl ...". As you can see in the line it references the variable $USER which is defined by USER=whoami. I cant seem to get the variable $USER into the line which is wrapped by the backticks ("`"). This is elementary i know but this is my first bash script and am at a loss.

Thanks for any assistance Experts.
0
Comment
Question by:CNCS_AUS
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 38781093
USER=`whoami`
0
 
LVL 14

Expert Comment

by:ThomasMcA2
ID: 38781139
There should also be a USER environment variable, so your script doesn't even need the USER= line.
0
 

Author Comment

by:CNCS_AUS
ID: 38781189
Thanks Guys -- the point isnt really how to get the user variable since i can echo $USER and get the whoami value. But i cant get the line #8 to use the $USER as expected.

my analogy is this - in PHP i would do something like:

$fname = frank;
$lname = theTank;

echo "my name is: ".$name." and my last name is ".$lname;

im assuming in bash shell i need to do similar:

WDRIVE="dscl /Active\\ Directory/THOMASNETDOM/All\\ Domains/ -read /users/".$USER." | grep SMBHome: | cut -c 10- | tr '\\' '/'`

I know the above doesnt work but this is what im thinking. I think my lack of bash scripting knowledge is painfully obvious here.

Again thank you all for assitance!
0
 

Author Closing Comment

by:CNCS_AUS
ID: 38781200
hey guys this was the answer -- i was wrongly returning the $USER and confusing my results.

Thanks all
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Create a default user profile for Mac OS X 10.7/10.8 Create a user account on OS X that will be a template for every other user of that computer. I usually call it “profile” and make it an administrator account for the time being. 1. Install a…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now