LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   read scripts (https://www.linuxquestions.org/questions/linux-newbie-8/read-scripts-358714/)

alchem 08-30-2005 11:42 PM

read scripts
 
Someone mentioned to me about making shell scripts and I wanted to read the ones on my distro (RH9).

As i attempt to shed some newbie skin i fin i'm typing find / -name ____ often and i'd like to write a script to speed up my learning while indulging my slackard ways.

Thanks

titopoquito 08-31-2005 05:45 AM

I think it would be easier to set an alias for this task (man alias). For writing bash scripts look at http://www.tldp.org/guides.html -- there is a guide called "Bash Guide for Beginners".

archtoad6 08-31-2005 10:41 AM

Other suggestions for reading system shell scripts.
 
A really laudable endeavor reading the system shell scripts.

Some other suggestions:
  • locate
  • Cruise /etc -- I like to use mc (Midnight Commander) for that:
    Code:

    mc /etc /etc
  • For a list of shell scripts in /etc:
    Code:

    # grep -RE '^#![[:space:]]*/bin/(ba)?sh' /etc/*  \
      |awk -F: '{print $1}'|less -S#20

  • To view them all in succession:
    Code:

    # less `grep -RE '^#![[:space:]]*/bin/(ba)?sh' /etc/* \
      |awk -F: '{print $1}'`

Notes
  • The '#' is to remind you to run these as root -- fewer errors & more access
  • Ignore all ":grep: ... No such file or directory" lines, they are going to stderr
  • RTfM on the things you don't understand here, it's a good opportunity to learn. less, grep, & awk are very useful tools, & I have deliberately not explained the options I used. (More chance for you to learn.:))
  • Keep a good bash reference handy as you read the scripts.
  • If you want to look at other directories, change '/etc/*'.
  • EDIT: Broke long "Code" lines w/ '\\' to minimize horizontal scrolling. Be sure to re-assemble properly.



alchem 08-31-2005 11:22 AM

archtoad6,
thanks! i wont be able to try until later....
i tried to locate the script run from the 'more' command by using find / -name more, hoping this would lead me to the actual script and when i tried to open the 'script' with vi, as determined by the results of find, i got junk printed.
i guess the commands you posted somehow make the scripts into human language as opposed to the machine language these files are in.

archtoad6 08-31-2005 11:42 AM

Scripts by definition are text files. You probably have been trying to look at binaries too.

BTW, after you are done w/ /etc/*, consider /bin/* & /sbin/*; they are mostly binaries, but there are a few scripts.

BTW2, the extension '.sh' is supposed to indicate a shell script, but is not mandatory. In *nix, file extensions are advisory only.


All times are GMT -5. The time now is 04:02 AM.