Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-10-2012
Registered User
 
Join Date: Jul 2012
Posts: 4
Thanks: 3
Thanked 1 Time in 1 Post
YANQ (Yet Another Newbie Question)

I have a directory "a b c/x y z"

I would like to assign it an environment variable so I can "cd" to it, as in:

A="a b c/x y z";export A

so that I can "cd $A".

I've tried single quotes, double quotes, backslashes and permutations thereof, but NOTHING works.

Any help would be graciously accepted.
Sponsored Links
    #2  
Old 07-10-2012
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,139
Thanks: 3
Thanked 954 Times in 933 Posts
It is working for me:
Code:
# a="a b/c d"
# cd $a
# pwd
/root/test/a b/c d

Can you post exact commands that you are using?
The Following User Says Thank You to bartus11 For This Useful Post:
wel51x (07-10-2012)
Sponsored Links
    #3  
Old 07-10-2012
Registered User
 
Join Date: Jul 2012
Posts: 4
Thanks: 3
Thanked 1 Time in 1 Post
here's what happens to me:

Code:
Winstons-MacBook-Pro:bh winstonlee$ a="a b/x y"
Winstons-MacBook-Pro:bh winstonlee$ cd $a
-bash: cd: a: No such file or directory
Winstons-MacBook-Pro:bh winstonlee$ ls -ls "a b"
total 0
0 drwxr-xr-x  2 winstonlee  staff  68 Jul 10 16:59 x y
Winstons-MacBook-Pro:bh winstonlee$


Last edited by Scrutinizer; 07-11-2012 at 02:50 AM.. Reason: please ue code tags
    #4  
Old 07-10-2012
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,139
Thanks: 3
Thanked 954 Times in 933 Posts
Hmmm... OSX? What shell are you using?
The Following User Says Thank You to bartus11 For This Useful Post:
wel51x (07-10-2012)
Sponsored Links
    #5  
Old 07-10-2012
Registered User
 
Join Date: Jul 2012
Posts: 4
Thanks: 3
Thanked 1 Time in 1 Post
dunno; does this help?



Code:
Winstons-MacBook-Pro:bh winstonlee$ echo ++++++++;env|sort;echo ++++++++
++++++++
Apple_PubSub_Socket_Render=/tmp/launch-BY8Q0h/Render
Apple_Ubiquity_Message=/tmp/launch-9h1fCp/Apple_Ubiquity_Message
BHTV15=/Users/winstonlee/Desktop/Apps/BrightHouse/iOS Projects/bhn-ios-1.5_05April_Defect697
BHTV2=/Users/winstonlee/Desktop/Apps/BrightHouse/AndroidProjects/bhn-ios-2-0
COMMAND_MODE=unix2003
DISPLAY=/tmp/launch-q5Y1id/org.x:0
HISTSIZE=4000
HOME=/Users/winstonlee
LANG=en_US.UTF-8
LOGNAME=winstonlee
OLDPWD=/Users/winstonlee
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
PWD=/Users/winstonlee/bh
SHELL=/bin/bash
SHLVL=1
SSH_AUTH_SOCK=/tmp/launch-WI9YBK/Listeners
TERM=xterm-256color
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=303.2
TERM_SESSION_ID=3D7D5A54-96ED-4FD8-A9C2-C0EDFC140744
TMPDIR=/var/folders/4w/kshc1x5n0qjd0yhn8k4c8w2c0000gn/T/
USER=winstonlee
_=/usr/bin/env
__CF_USER_TEXT_ENCODING=0x1F5:0:0
++++++++
Winstons-MacBook-Pro:bh winstonlee$

---------- Post updated at 05:12 PM ---------- Previous update was at 05:11 PM ----------

duh, I guess it's bash

---------- Post updated at 05:12 PM ---------- Previous update was at 05:12 PM ----------

OS is Lion

Last edited by methyl; 07-10-2012 at 05:48 PM.. Reason: code tags and highlight important line
Sponsored Links
    #6  
Old 07-10-2012
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,139
Thanks: 3
Thanked 954 Times in 933 Posts
Try KSH maybe like this:
Code:
# ksh
# a="a b"
# cd "$a"

Sponsored Links
    #7  
Old 07-10-2012
methyl methyl is offline Forum Staff  
Moderator
 
Join Date: Mar 2008
Posts: 6,388
Thanks: 286
Thanked 668 Times in 640 Posts
In bash or ksh, quotes are so important when a string contains space characters:


Code:
A="a b/x y"
cd "$A"

The double quotes are known as "soft quotes" because you can still do variable substitution. You cannot do variable subtitution within single quotes.

Mini explanation. The cd command only expects one parameter. The default parameter separator is white space. Therefore without the double quotes it only read the a .

I don't know what Shell @bartus11 has but it is certainly unusual.

Last edited by methyl; 07-10-2012 at 05:50 PM.. Reason: change case of variable to make "a" unambiguous
The Following User Says Thank You to methyl For This Useful Post:
wel51x (07-10-2012)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
perl newbie . &&..programming newbie (question 2) xytiz Shell Programming and Scripting 1 05-07-2009 12:26 PM
UNIX newbie NEWBIE question! Hanamachi UNIX for Dummies Questions & Answers 4 03-28-2009 04:10 PM
SED question: newbie here. jigarlakhani Shell Programming and Scripting 2 07-01-2008 02:57 AM
Newbie question Eduard Programming 1 06-09-2008 06:21 AM
Very new newbie question Split100 UNIX for Dummies Questions & Answers 4 11-29-2005 03:49 PM



All times are GMT -4. The time now is 05:57 PM.