Solved

basic bash scripting help with line evaluation

Posted on 2013-01-15
4
550 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

There is a security feature on iOS devices that is nearly impenetrable when it has been activated.  This article will provide some possible solutions as well as necessary steps to take to ensure you do not end up with a locked device.
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 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

18 Experts available now in Live!

Get 1:1 Help Now