Solved

basic bash scripting help with line evaluation

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

815 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

8 Experts available now in Live!

Get 1:1 Help Now