Go Back   openSUSE Forums > Archives > SF Archives > ARCHIVES - Programming & Scripting
Forums FAQ Members List Search Today's Posts Mark Forums Read


ARCHIVES - Programming & Scripting A place to discuss website design, programming, shell scripts, etc

 
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 20-May-2008, 07:42
Geofoxer
Guest
 
Posts: n/a
Default

Hello all,

I have recently started playing around with scripting in linux. I would like to write a small value which would allow me to automatically change from the current directory to the directory defined by the value... for example:

Code:
$home=`cd /home/suse/desktop`
I have tried other variations but have not had any luck. Any suggestions would be greatly appreciated. Thanks...
  #2 (permalink)  
Old 20-May-2008, 07:57
ken_yap
Guest
 
Posts: n/a
Default

First of all, you cannot change the directory by assigning to $home. Secondly a cd inside a script cannot change the directory of the outside shell because the change directory is only effective within the script which is a child shell. You have to do it with an alias:

alias cdhome='cd $HOME'
  #3 (permalink)  
Old 20-May-2008, 08:16
Geofoxer
Guest
 
Posts: n/a
Default

Sweet, that worked. Thanks for the quick reply.

Just noticed that this does not work in all terminals, are these commands binded to the terminal where the commands were created? How can you make them also available for all normal users?
  #4 (permalink)  
Old 20-May-2008, 08:59
mooreted
Guest
 
Posts: n/a
Default

Quote:
Sweet, that worked. Thanks for the quick reply.

Just noticed that this does not work in all terminals, are these commands binded to the terminal where the commands were created? How can you make them also available for all normal users?
[/b]
In each user's home directory there is a file called .bashrc. You can edit this file to add your aliases. Since there is a different .bashrc file for each user, each user can have their on bash configurations.

For global aliases you can use the /etc/bash.bashrc file.

  #5 (permalink)  
Old 21-May-2008, 04:04
Geofoxer
Guest
 
Posts: n/a
Default

Cool, thanks for the quick post... I have placed my aliases in the global bash file, but they do not work. Is there a specific place in the config file where I have to place these alias's so it will be reconized?
  #6 (permalink)  
Old 21-May-2008, 10:33
mooreted
Guest
 
Posts: n/a
Default

Quote:
Cool, thanks for the quick post... I have placed my aliases in the global bash file, but they do not work. Is there a specific place in the config file where I have to place these alias's so it will be reconized?
[/b]
No. I usually put them at the and of the .bashrc file such as:

alias ll='ls -l'
alias la='ls -a'

If /etc/bash.bashrc doesn't work try creating /etc/bash.bashrc.local and using that.

I haven't set any gloabal aliases in ages as I usually have different ones for root and user. They may have changed things over the years. If I am wrong I hope someone will correct me so I know.

 

Bookmarks

Thread Tools
Display Modes

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




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2