LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-05-2014, 09:02 PM   #1
scoobyjax
LQ Newbie
 
Registered: Aug 2014
Posts: 3

Rep: Reputation: Disabled
How can I create an environmnetal variable that points to a directory?


I'm trying to figure out how I can make an environmental variable for 6 users that points to a specific directory. I'm not sure how to do that and for some reason I keep thinking "alias" but I was told to do this with an environmental variable. for example, no matter where my users are on the system, I want them to have an environmental variable that points them towards /usr/local/class_ideas Can anyone show me how to do this? Much appreciated in advance!
 
Old 08-05-2014, 09:40 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

you can put it in /etc/profile, which will be sourced for all users (using bourne style shells like bash, ksh, zsh etc). Often /etc/profile has a little loop that sources all /etc/profile.d/*.sh files, if yours has that (or if you add it yourself) it's better to make a new file and put it there. Eg in /etc/profile.d/dirvariable.sh
Code:
export CLASS_IDEAS="/usr/local/class_ideas"
Then users can do
Code:
cd $CLASS_IDEAS
but I don't see this as being much more convenient than cd'ing directly. Ie.
Code:
cd /usr/local/class_ideas
If this should only be set for specific users you can use an if statement that checks the username.

HTH,

Evo2.
 
Old 08-05-2014, 09:59 PM   #3
scoobyjax
LQ Newbie
 
Registered: Aug 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
Hi,

you can put it in /etc/profile, which will be sourced for all users (using bourne style shells like bash, ksh, zsh etc). Often /etc/profile has a little loop that sources all /etc/profile.d/*.sh files, if yours has that (or if you add it yourself) it's better to make a new file and put it there. Eg in /etc/profile.d/dirvariable.sh
Code:
export CLASS_IDEAS="/usr/local/class_ideas"
Then users can do
Code:
cd $CLASS_IDEAS
but I don't see this as being much more convenient than cd'ing directly. Ie.
Code:
cd /usr/local/class_ideas
If this should only be set for specific users you can use an if statement that checks the username.

HTH,

Evo2.
I'm not sure I understand. I'm logged in as root. From a command prompt I typed: CLASS_IDEAS="/usr/local/class_ideas, then I typed: export CLASS_IDEAS
is that what you mean? After I did: echo $CLASS_IDEAS I did not get any value for the variable so I'm doing something wrong
 
Old 08-05-2014, 10:08 PM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,
Quote:
Originally Posted by scoobyjax View Post
I'm not sure I understand. I'm logged in as root. From a command prompt I typed: CLASS_IDEAS="/usr/local/class_ideas, then I typed: export CLASS_IDEAS
is that what you mean?
It's not what I wrote, nor what I meant. I wrote and meant that you could create a file called /etc/profile.d/dirvariable.sh that would contain
Code:
export CLASS_IDEAS="/usr/local/class_ideas"

Quote:
Originally Posted by scoobyjax View Post
After I did: echo $CLASS_IDEAS I did not get any value for the variable so I'm doing something wrong
That variable would be set if you made the file as described above after a new log in (assuming what I wrote about /etc/profile is true - you should check).

Evo2.
 
Old 08-05-2014, 10:20 PM   #5
scoobyjax
LQ Newbie
 
Registered: Aug 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
Hi,

It's not what I wrote, nor what I meant. I wrote and meant that you could create a file called /etc/profile.d/dirvariable.sh that would contain
Code:
export CLASS_IDEAS="/usr/local/class_ideas"


That variable would be set if you made the file as described above after a new log in (assuming what I wrote about /etc/profile is true - you should check).

Evo2.

You Rock!!!!!! Thank you. I'm taking an intro class to linux and I'm pretty lost. Any chance I can ask you one more simple question? How can a make sure that ssh is enabled so my users can connect remotely to the server I'm working on? I have a feeling it is enabled but don't know how to check. Thanks again!
 
Old 08-05-2014, 10:54 PM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

the most complete answers to that question are "disto specific". Ie different answers for different linux distributions. I suggest you open a new thread with that question. Please include what distro you are using and also make sure it is clear it is a homework question. That way you will get responses that will help you understand the general ideas that are associated with the question, not just get the "right answer" and then be stumped when asked a similar question in the future.

Cheers,

Evo2.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to copy specific directory based on variable to folder with that variable name fluxburn Programming 7 01-07-2010 07:59 PM
How do I create mount points using the terminal? nosloj Linux - Newbie 4 11-12-2009 03:23 PM
Variable that points to current cdrom on multiple systems perlabsrat Linux - Newbie 4 06-20-2008 04:55 PM
create a variable in the .bashrc file in my home directory coldbeerz Linux - Newbie 2 12-14-2007 09:48 AM
Can't create .ISO with full directory paths (-graft-points?) tdp05 Linux - Newbie 0 08-17-2004 04:01 PM


All times are GMT -5. The time now is 04:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration