LinuxQuestions.org
Register a domain and help support LQ
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 03-25-2004, 05:25 AM   #1
tired
Member
 
Registered: Jan 2004
Location: Wales UK
Distribution: Suse 9.0, Slackware 10, FC3
Posts: 51

Rep: Reputation: 15
Question Command Line Help


I use a command on a semi regular basis thats a bind to type out. Is there a way of automating it? I'm not familiar with programming or scripting so any pointers would be great. I've currently saved it as a text file and paste it in when required, but to be able to just type a shortcut for it like ls or whatever would be great.

Thanks
 
Old 03-25-2004, 05:29 AM   #2
:RoB:JoB:
LQ Newbie
 
Registered: Mar 2004
Distribution: Mandrake 9.1
Posts: 3

Rep: Reputation: 0
so you have it in a file, I'll call it "text". Wouldn't

./text

do it?

That is, typing ./text at the comand prompt. You could have the file in your user's directory under home, and then all you'd have to do is open a terminal and type ./text. Your file might resemble this:

cd Desktop/YourFolder/YourPathYouMightNeed
<Your stuff you do>

I don't know for sure if that works, and I bet it's not the best way either. I'm a newbie too, I'm just trying to give back.
robjob

Last edited by :RoB:JoB:; 03-25-2004 at 05:39 AM.
 
Old 03-25-2004, 07:00 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
You will want the first line of the script to indicate which shell you are using.

For example for bash:
#!/bin/bash
If your script takes a parameter, use '$1' as the parameter.


Then after you save the script, you need to make it executable with the command:
chmod u+x <filename>

You could also create a directory called 'bin' in your home directory and add the path in your ~/.bash_profile file. This file is executed when you log-in.

That is what I did with mine:
Code:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME
 
Old 03-25-2004, 10:37 AM   #4
jeffreybluml
Member
 
Registered: Mar 2004
Location: Minnesota
Distribution: Fedora Core 1, Mandrake 10
Posts: 405

Rep: Reputation: 30
hmmm, can't you just make a alias for it in /etc/bashrc? For instance...

alias do_it='whatever really long command you have to type'

and then type "bash" (no quotes) at the command line to re-source your bash script...

Or perhaps I just don't understand the problem at hand...

Good luck!
 
Old 03-25-2004, 12:01 PM   #5
tired
Member
 
Registered: Jan 2004
Location: Wales UK
Distribution: Suse 9.0, Slackware 10, FC3
Posts: 51

Original Poster
Rep: Reputation: 15
Cool

Thanks for the replies.

I was able to use the alias option and it works a treat
 
Old 03-25-2004, 12:34 PM   #6
tired
Member
 
Registered: Jan 2004
Location: Wales UK
Distribution: Suse 9.0, Slackware 10, FC3
Posts: 51

Original Poster
Rep: Reputation: 15
Just when you thought it was safe.......

For some reason when I log off the alias is lost, typing bash at the prompt has not done the job, is this a peculiarity of SuSe??
 
Old 03-25-2004, 02:00 PM   #7
jeffreybluml
Member
 
Registered: Mar 2004
Location: Minnesota
Distribution: Fedora Core 1, Mandrake 10
Posts: 405

Rep: Reputation: 30
sounds like perhaps you're not using a bash shell. I am a total newbie, so I am not familiar with any other shells. Nor am I familiar with Suse.

Do you have any idea what kind of shell you're using?

If I understand correctly, the alias worked at some point. Could you detail what you did when you created the alias, what you did right after creating it that made it work, and finally what you did between the time it worked and when it stopped working.

I'll do my best to help...

Good luck...
 
Old 03-25-2004, 02:32 PM   #8
tired
Member
 
Registered: Jan 2004
Location: Wales UK
Distribution: Suse 9.0, Slackware 10, FC3
Posts: 51

Original Poster
Rep: Reputation: 15
Angry

cheers mate.

i did exactly as you posted.

i'm sure i'm using bash. it just seems that the alias only works until i close the terminal. when i try again bash reports that the command is not found. there must be a file somewhere that needs altering but i don't know which one.
 
Old 03-25-2004, 02:47 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
No need to be grumpy ...

A) there's the bash history ...
Ctrl-R and starting to type a part of the command will
bring it back.
B) You can put the alias definition in ~/.bashrc
or ~/bash_profile (whichever is appropriate on
your machine)


Cheers,
Tink
 
Old 03-25-2004, 03:59 PM   #10
tired
Member
 
Registered: Jan 2004
Location: Wales UK
Distribution: Suse 9.0, Slackware 10, FC3
Posts: 51

Original Poster
Rep: Reputation: 15
Red face

I'm always clicking on the wrong one, sorry.

I'll try that thanks again
 
Old 03-26-2004, 04:56 AM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
The ~/.bash_profile command is executed when you first log on. ~/.bashrc is executed when starting an interactive shell. You probably want to add the alias definition in ~/.bash_profile so that it is available as soon as you log on.

If you want the alias defined for all users. Then add the alias definition to /etc/profile.d/bash.sh.

Last edited by jschiwal; 03-26-2004 at 04:57 AM.
 
Old 03-26-2004, 06:23 AM   #12
tired
Member
 
Registered: Jan 2004
Location: Wales UK
Distribution: Suse 9.0, Slackware 10, FC3
Posts: 51

Original Poster
Rep: Reputation: 15
Thanks for all this help.

I can find bash.bashrc but not bash_profile. I found profile.d but theres no bash.sh, there. Can I simply make one?
 
Old 03-26-2004, 04:05 PM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Yep, you can.
 
Old 03-28-2004, 08:50 AM   #14
tired
Member
 
Registered: Jan 2004
Location: Wales UK
Distribution: Suse 9.0, Slackware 10, FC3
Posts: 51

Original Poster
Rep: Reputation: 15
erhm, i think you know whats coming now........

how do i do that, is it a simple text file?
 
Old 03-28-2004, 09:04 AM   #15
DrOzz
Senior Member
 
Registered: May 2003
Location: Sydney, Nova Scotia, Canada
Distribution: slackware
Posts: 4,185

Rep: Reputation: 59
well you can do 1 of 2 things ... or both i guess ...
we'll pretend your using vim as your text editor so if you type :
vim .bashrc
and then you save that file, then it will be there ...

or you can simply type from a prompt :
touch .bashrc

and it will be there, obviously with nothing in it ...
and then you would have to open it and add whatever it is you want ..
 
  


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
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 08:19 PM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 08:45 PM
51 characters only in the 1st Line of command line eggCover Linux - General 2 07-29-2004 02:28 PM
Command to display whole filestructure hierarchy f/ command line? mjewell Linux - Newbie 10 01-19-2004 11:48 AM
Where is Command line utility for Cups and command tutorial mossy Linux - Software 8 01-16-2004 01:24 AM


All times are GMT -5. The time now is 08:27 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