The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
macro expansion in vi editor cleopard High Level Programming 0 05-01-2008 10:06 AM
Perl: Filename expansion? davidg Shell Programming and Scripting 6 01-14-2008 03:48 PM
Pattern expansion problem njoshi Shell Programming and Scripting 5 04-24-2007 12:28 PM
AIX Expansion CD almuwatta AIX 0 06-23-2005 05:07 PM
ksh on HP-UX -- variable expansion dangral UNIX for Dummies Questions & Answers 4 02-08-2005 12:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-15-2008
Rledley Rledley is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 7
Question ~ expansion in printf

Hi,

I have a script that at one point prints to a file as follows:

Code:
printf -- $2 > ~/.mydir/$1
The idea is to print to a hidden directory .mydir in my home directory. I've already sanitized the inputs and $1 is in the format
Code:
path1/path2/filename
and $2 is some user input.

When I run this on my Mac, there's no problem and it works great. When I upload it to the system where I eventually intend to use it, however, it doesn't work quite right. It writes the correct user input to a file located at:
Code:
my_present_directory/~/.mydir/filename
where my_present_directory is wherever I upload the script file to. It's actually making a directory called "~".

Any ideas on how to get this work work as intended?

Thanks!
  #2 (permalink)  
Old 11-15-2008
geekosaur geekosaur is offline
Registered User
  
 

Join Date: Oct 2008
Location: Pittsburgh, PA, USA
Posts: 20
Code:
~
is only guaranteed to work in interactive shells (and not even then if it's the old Bourne shell as on Solaris).
Code:
$HOME
is the correct portable way to refer to your home directory.
  #3 (permalink)  
Old 11-15-2008
Rledley Rledley is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 7
Thumbs up

That worked great. Thanks!
Closed Thread

Bookmarks

Tags
expansion, home directory, printf, redirection, scripting

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0