Solved

basic bash scripting help with line evaluation

Posted on 2013-01-15
4
559 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

691 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