save variables and aliases

Hi,

Here is the issue:

I create saome variables to makea shotcut to some directories I go frequently (so, I then I type, e.g. cd $P_DIR). Of Course before that I put a valid value into P_DIR variabe.

Also, alias, as

alias cls=clear

So, I type cls, and is the same as the commando clear (but shorter)

What I want to do is that those variables as aliases stay in the computer when I reboot or turn off and turn on.

So, I put “somewhere” (this is the place(s) maybe one for variables, and other for aliases, turn of the computer, and when I turn on, the aliases and variables are still there.

thanks for any feedback,

agunet74:)

Even better still, you use a text editor to enter those alias commands and variable assignments into a file that is read by bash when it is started up and they will be available when you run bash. One such file is .alias in your home directory (note the . in front). For example you put lines like:

alias h=history
export CVS_RSH=ssh

and so forth in it and next time you login or start a bash shell, they will be available.

PS: ~/.alias is not a file that’s documented as read by bash if you are wondering, but the default .bashrc (which is normally read by bash) on openSUSE has this line at the end:

test -s ~/.alias && . ~/.alias

It didn’t work.

That sentences din’t save me any variable or alias.

Any other suggestion ?

Put them in .bashrc directly

What exactly did you do? Do you understand that you can’t “save” your current settings, but you write them down so that they are read in by each shell? So you have to put all the assignments you made into that file. Any new ones you make during a session are not “saved”.

alias put them on .bashrc works fine!

Now … I want to set a value to vriable and when reboot my system still have that value.

I know, maybe there is a file or something. I’'ve done it before on unix AIX and unix HP.

This has to be the same. How can I save values to variables ? When I say “save” can be “write on a file”.

thanks

agunet74

You would have to dump the variable assignments to a file and then arrange to read them in again later. This is a scripting problem. There are no ready made commands for this because usually people put what they want to be “permanent” in .bashrc or .aliases and don’t want to carry over the assignments from a previous session. But the tools are there to do this.

But the tools are there to do this.

What tools are you talking about Flux ?

No, shell scripts.

When I meant flux, I meant ken_yap. I thought flux was his nick! lol! lol!

Back to the issue:

I don’t understand or I understand less than the beginning of this forum.

Is there a script that storage variables ? If so, whi is it ? In which directory can be found?

If not… How can I make one and which name shold I save it ?

(sorry if my english is not very good)

thanks again KEN!! :slight_smile:

There no such ready made scripts, you will have to write them. If you don’t know shell scripting, you will have to learn. Here are some hints:

The shell builtin command “set” will print out all variable and function assignments, and the output can be directed to a file. Similarly the command “alias” prints out all aliases. Those assignments can be read in again from a file with the “source” command. However you want to be selective with what you read in again. You could easily lock yourself out of the computer if you get your shell to automatically read everything in, including assignments that are mistakes.

You can test this.
create a .alias file in your home directory
add some aliases like

alias zy="sudo zypper"

then save and exit

chmod +x .alias
source .bashrc

And then works here

zy

On 12/01/2015 03:36 PM, speedytux wrote:
>
> You can test this.
> create a .alias file in your home directory
> add some aliases like
>
> Code:
> --------------------
> alias zy=“sudo zypper”
> --------------------
>
> then save and exit
>
> Code:
> --------------------
> chmod +x .alias

This step is not necessary just use:

… .alias

to have the file re-sourced.


Ken
linux since 1994
S.u.S.E./openSUSE since 1996