Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

basic bash scripting help with line evaluation

Posted on 2013-01-15
4
Medium Priority
?
561 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
While there are many new features for iOS 11, these are the five that can improve your digital lifestyle.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

610 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