2

within script the attempt here is to remove the : and then revert the / to \ within the print out

currently I have to display the linux path: The home directory is located here: rtp1-filer-ns:/homedir-private/private007/user

and would like to reformat as for my users ease Windows path to home directory: \rtp1-filer-ns\homedir-private\private007\user

currently this part of the script is as follows

echo "The shell is: `ypmatch $EndUser passwd | awk -F\: '{ print $7 }'`"
echo ""
echo "The home directory is located here:"
   ypmatch $EndUser auto_home 
echo ""
echo "Windows path to home directory:"
echo "\\\\`ypmatch $EndUser auto_home | awk -F':' '{print $1}'`\\$EndUser"

gives me the print out of :

The home directory is located here:
rtp1-filer-ns:/homedir-private/private007/user

Windows path to home directory:
\\rtp1-filer-ns\user

assuming i can use sed /awk something of the sorts , open for suggestions $EndUser is a defined var

1

With bash

First approach - use parameter substitution

#use command substitution to set command output into variable var
var=$(ypmatch $EndUser auto_home)
#strip out the first :
var=${var/:}
#replace all instances of / with \
var=${var//\//\\}
echo $var

rtp1-filer-ns\homedir-private\private007\user

Second approach - use arrays

# Set path components into array frags
IFS=/ read -a frags < <(ypmatch $EndUser auto_home)

# Strip ":" off rtp1-filer-ns
frags[0]="${frags[0]%:}"

# Set IFS to \ to print frags \-separated
echo "$(IFS=\\ ;printf '%s\n' "${frags[*]}";)"

rtp1-filer-ns\homedir-private\private007\user
  • Awesome ! works like a charm ! Thanks Much! – Tim M. Mar 4 '16 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.