Member_2_4942450
asked on
Getting error when creating a simple alias script
Here is my script but when I run it I get an error
The last bit of code is
Aparently when I run this it says lsf command not found.
Screen-shot-2010-09-06-at-7.43.3.png
The last bit of code is
Aparently when I run this it says lsf command not found.
Screen-shot-2010-09-06-at-7.43.3.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try it on the command line just to test.
Then type alias and see if its listed.
Then type alias and see if its listed.
ASKER
Did that
everything I tried on a command line by line base worked.
When I run it in a script it doesn't can't explain it myself but this was my assignment given to me.
Write a script that does the following and run it from your home directory.
Use the cat utility to write the contents of file /etc/protocols to a new file called protocolsFile.
Create a new directory called top
Move file protocolsFile to directory top.
Change to directory top.
Display the current directory name
List the files in the current directory.
Use the cat utility to append the contents of file /etc/passwd to file protocolsFile.
Display just the number of lines in file protocolsFile
Display just the number of words in file protocolsFile
Delete file protocolsFile.
Change to your home directory. Remember your home directory is not /home, it’s the directory you log in to. (hint: use a command that will work for any user on any system)
Remove the top directory (hint: look at the rmdir command)
Create an alias for the ls –F and call it lsf.
Execute the lsf command.
Start a second shell.
Execute the command that shows all the processes running on that terminal.
everything I tried on a command line by line base worked.
When I run it in a script it doesn't can't explain it myself but this was my assignment given to me.
Write a script that does the following and run it from your home directory.
Use the cat utility to write the contents of file /etc/protocols to a new file called protocolsFile.
Create a new directory called top
Move file protocolsFile to directory top.
Change to directory top.
Display the current directory name
List the files in the current directory.
Use the cat utility to append the contents of file /etc/passwd to file protocolsFile.
Display just the number of lines in file protocolsFile
Display just the number of words in file protocolsFile
Delete file protocolsFile.
Change to your home directory. Remember your home directory is not /home, it’s the directory you log in to. (hint: use a command that will work for any user on any system)
Remove the top directory (hint: look at the rmdir command)
Create an alias for the ls –F and call it lsf.
Execute the lsf command.
Start a second shell.
Execute the command that shows all the processes running on that terminal.
What is the output of
bash -x assignment2
bash -x assignment2
ASKER
You may have to make it a global alias
ASKER
how would i do that?
What distro are you using?
ASKER
whats is "distro"
I am running Centos OS on one machine and solaris 10 on the other if thats what you mean
using bash
I am running Centos OS on one machine and solaris 10 on the other if thats what you mean
using bash
Try this in your script, instead of:
alias lsf='ls -F'
do this:
echo "alias lsf='ls -F'" >> ~/.bashrc
source ~/.bashrc
ASKER
did not work
same erro line 15 lsf: command not found
same erro line 15 lsf: command not found
Hmmm.. Let me log into my box and try this.
ASKER
ok will be standing by
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I just tested the above and it works great on my fedora box... For an explanation of why this is read the following...
http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/aliases.html
http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/aliases.html
ASKER
ok that worked
but when I ran it
It followed the script all the way till
#sh
then I had to type in exit
and it then ran the ps
I need it to run the ps inside the sh.
without me having to type in exit
but when I ran it
It followed the script all the way till
#sh
then I had to type in exit
and it then ran the ps
I need it to run the ps inside the sh.
without me having to type in exit
Someone beat me to the expand_aliases option.
Why do you need to start a new sh in your script?
Why do you need to start a new sh in your script?
ASKER
it's what my directions call for class assignment
Wow, your really making us work for the 500 points! :)
This is a good learning exercise, your teacher is really putting you through the paces. :)
This is not a simple thing to do, I have to log back into my box and give it a go.
This is a good learning exercise, your teacher is really putting you through the paces. :)
This is not a simple thing to do, I have to log back into my box and give it a go.
Ok, so I tried a few things but the only thing I can come up with it to execute a second shell script. I am not sure if he wants you to fork processes or if this will be ok with him.
but you can create a second script with just one line in it:
ps
you can name is newshell
then in your first script add this line at the end:
./newshell
This will create a new shell and show the processes.
but you can create a second script with just one line in it:
ps
you can name is newshell
then in your first script add this line at the end:
./newshell
This will create a new shell and show the processes.
ASKER
to create a new shell we had learned
command sh
sh
now when the script runs it runs
and creates the 2nd shell
but I have to type in exit
for the ps command to then exit
last lines of code are
command sh
sh
now when the script runs it runs
and creates the 2nd shell
but I have to type in exit
for the ps command to then exit
last lines of code are
lsf
sh
ps
ASKER
almost like the script stops at the 2nd shell with the sh
But then I have to type in exit at the 2nd shell for the ps to run
and I think he wants the ps to be running in the 2nd shell
he hasn't talked about creating 2nd scripts and executing a command from one script to the other yet.
But then I have to type in exit at the 2nd shell for the ps to run
and I think he wants the ps to be running in the 2nd shell
he hasn't talked about creating 2nd scripts and executing a command from one script to the other yet.
you could always do
lsf
sh -p ps
lsf
sh -p ps
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what the -c mean?
Let me try this
Let me try this
ASKER
Bingo Yeeeeeeeeeee
I finally got it right on
I just need to know what the "sh -c" mean
thanks so much and staying with me on this
I finally got it right on
I just need to know what the "sh -c" mean
thanks so much and staying with me on this
Type
man bash
to see all the options for bash.
-c means run the following command
man bash
to see all the options for bash.
-c means run the following command
ASKER
Then I don't know why its giving me
See screen shot
Screen-shot-2010-09-06-at-8.13.1.png