[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

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
0
sobeservices2
Asked:
sobeservices2
  • 13
  • 10
  • 5
3 Solutions
 
savoneCommented:
Should work, are those backticks or single quotes? You should be using single quotes.

alias lsf='ls -F'

0
 
sobeservices2Author Commented:
They are single quotes

Then I don't know why its giving me
See screen shot

Screen-shot-2010-09-06-at-8.13.1.png
0
 
savoneCommented:
Try it on the command line just to test.

Then type alias and see if its listed.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
sobeservices2Author Commented:
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.
0
 
TintinCommented:
What is the output of

bash -x assignment2
0
 
sobeservices2Author Commented:
Here is the output of
bash -x assignment2

Screen-shot-2010-09-06-at-8.30.3.png
0
 
savoneCommented:
You may have to make it a global alias
0
 
sobeservices2Author Commented:
how would i do that?
0
 
savoneCommented:
What distro are you using?
0
 
sobeservices2Author Commented:
whats is "distro"

I am running Centos OS on one machine and solaris 10 on the other if thats what you mean

using bash
0
 
savoneCommented:


Try this in your script, instead of:

alias lsf='ls -F'

do this:

echo "alias lsf='ls -F'" >> ~/.bashrc
source ~/.bashrc


0
 
sobeservices2Author Commented:
did not work
same erro line 15 lsf: command not found
0
 
savoneCommented:
Hmmm.. Let me log into my box and try this.
0
 
sobeservices2Author Commented:
ok will be standing by

0
 
savoneCommented:
AHA!



try this:

alias lsf='ls -F'
shopt -s expand_aliases
lsf
0
 
savoneCommented:
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

0
 
sobeservices2Author Commented:
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
0
 
TintinCommented:
Someone beat me to the expand_aliases option.

Why do you need to start a new sh in your script?
0
 
sobeservices2Author Commented:
it's what my directions call for class assignment
0
 
savoneCommented:
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.


0
 
savoneCommented:
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.

0
 
sobeservices2Author Commented:
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
lsf
sh
ps

Open in new window

0
 
sobeservices2Author Commented:
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.
0
 
TintinCommented:
you could always do

lsf
sh -p ps
0
 
TintinCommented:
typo, I meant

sh -c ps
0
 
sobeservices2Author Commented:
what the -c mean?
Let me try this
0
 
sobeservices2Author Commented:
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
0
 
TintinCommented:
Type

man bash

to see all the options for bash.

-c means run the following command
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 13
  • 10
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now