LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 04-27-2008, 08:43 PM   #1
Ricio
Member
 
Registered: Sep 2003
Location: Colombia
Distribution: Debian
Posts: 220

Rep: Reputation: 30
Question Linux scripting, is it really all posible?


What cant be scripted in linux?
Thats a first question, and another one would be

how to script ntfsresize and fdisk, cfdisk, and sfdisk? is there any tutorials that would help me do some scripting with these commands?
 
Old 04-27-2008, 09:27 PM   #2
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
Pretty much anything can be scripted.

For information on the commands you listed, check the man pages.

I would suggest that you learn to write bash scripts first, and then start trying to script those commands. Since they are tools that actually modify your disk partitions, there is the potential for you to lose data if you don't know what you are doing.

--Ian
 
Old 04-27-2008, 10:11 PM   #3
linuxnoob001
LQ Newbie
 
Registered: Mar 2008
Location: Australia
Distribution: Fedora Core 5
Posts: 14
Blog Entries: 1

Rep: Reputation: 0
I agree with IBall. Bash scripting comes first there is a free site which teaches bash basics. search in google for it tldp.org/howto
 
Old 04-28-2008, 12:01 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Well, Bash certainly has a lot of power, but don't expect--for example--to do a lot of math. Bash is klutzy with simple arithmetic and does not do floating point--much less any trig or other stuff.

Bash is for orchestrating the functions of the operating system and for writing basic utilities. Any more complex task will be better with other tools--C, Python, etc.
 
Old 04-28-2008, 04:34 AM   #5
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
Theoretically you can do anything with it, but it's best used for simple task automation, so that you don't have to type so much into the shell to get it to do what you want.

Good tutorials are:
http://tldp.org/LDP/abs/html/
http://www.grymoire.com/Unix/
 
Old 04-28-2008, 05:31 AM   #6
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia 4
Posts: 740

Rep: Reputation: 35
Something I discovered recently is that you can write scripts in Python too. I find Python way more intuitive and you can really do anything with it. Most distributions come with Python apparently; it's powerful, about the easiest language I've ever learned and isn't arcane like bash can be at times.

Nice article here.
 
Old 04-28-2008, 08:24 AM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by DiBosco View Post
Something I discovered recently is that you can write scripts in Python too.
Well, yes.......Python is a scripting language!!

(I'm using scripting synonymously with interpreted--perhaps that is semantically impure)

The big difference is that a Python script goes thru an extra step (Python interpreter) and so---depending on the task--could be slower.

I REALLY like the syntax of Python--until I get to some of the more esoteric object constructs. (Object-oriented programming still has trouble sticking to my aging brain.)
 
Old 04-28-2008, 08:48 AM   #8
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia 4
Posts: 740

Rep: Reputation: 35
Quote:
Originally Posted by pixellany View Post
Well, yes.......Python is a scripting language!!
Yes, I should qualify that statement. I didn't realise you could use it to run bash-like scripts! I know it seems obvious now, but...

I have written quite a few simple Python scripts where time isn't the big issue. Agree with you about OO stuff!
 
Old 04-28-2008, 04:20 PM   #9
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,053

Rep: Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881
Quote:
Originally Posted by Ricio View Post
What cant be scripted in linux?
Well, so far, I haven't managed to script "ignore the pointless questions in LQ" (but then I'm not really trying, s'pose).

Quote:
but don't expect--for example--to do a lot of math. Bash is klutzy with simple arithmetic and does not do floating point--much less any trig or other stuff.
Well, bash itself can't really do fp/transcendentals, but you can always push the numbers through bc/dc or something (I think there is another one whose name I've forgotten). And I'm sure that you can force, say, awk (or emacs) to do math of idiotic complexity, if you really want to (but I don't).

Although by that point, I've usually got to the point that I think that something like Python would be a better idea.
 
Old 04-28-2008, 09:39 PM   #10
Ricio
Member
 
Registered: Sep 2003
Location: Colombia
Distribution: Debian
Posts: 220

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by salasi View Post
Well, so far, I haven't managed to script "ignore the pointless questions in LQ" (but then I'm not really trying, s'pose).
Good luck with that script salasi, believe me I dont ask questions that I dont care for an answer, that would be pointless.

Still thanks for your answer on the mathematics part! =)

Last edited by Ricio; 04-28-2008 at 09:41 PM.
 
Old 04-28-2008, 11:14 PM   #11
fancylad
Member
 
Registered: Mar 2008
Distribution: slackware
Posts: 175

Rep: Reputation: 19
Just to point out, if you need to do floating-point calculations in a shell script you can use bc. Example:

Quote:
matt@debian:~$ echo "scale=10; 1 / 3" | bc
.3333333333
I believe you can do pretty much everything (within reason) with shell scripting, the reason being is that there are so many amazing utilities at your disposal (ie bc). I think the biggest draw back would be portability and maybe performance.
 
Old 04-29-2008, 07:40 AM   #12
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
You can also do floating point arithmetic with awk if you don't have bc, but bc is preferred.
 
Old 04-29-2008, 07:54 AM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
matt@debian:~$ echo "scale=10; 1 / 3" | bc
.3333333333
for those that don't enjoy reading hieroglyphics:

python
>>> 1.0/3.0
0.33333333333333331
 
Old 04-29-2008, 10:59 AM   #14
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
If you're familiar with C you can do:

Code:
echo | awk '{ printf( "%.10f\n", 1/3 ) }'
 
Old 04-30-2008, 08:22 AM   #15
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 7,162

Rep: Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205
One of the very nicest features of Unix is the so-called "shebang." If you look at many programs, you'll discover that it is actually a text file, a script of some kind, which begins with a line such as:
Code:
 #!/usr/bin/perl
The essential idea here is that, when the file begins with ("#!") shebang, that's the name of the program that should be invoked .. invisibly to you .. to run this program.

This is the pathname to a program, such as Perl in this case; it can also be a more-generic ("computer, you go find it for me...") type of reference.

So... what this allows you to do is to quickly and easily write programs in script-languages: pick one. In the Unix/Linux environment, you can more-or-less count on Perl, Python, and PHP; and probably Ruby. All four of these are high powered, fully-featured programming languages with very excellent implementations.

The command-interpreter (most-frequently bash, but as-usual "you have many choices") also has its own built-in scripting capabilities, up to a point. This may be why all command-line scripting is often colloquially referred-to as "bash scripting." But you are not limited-to that scripting capability, which in my mind is appropriate only for the simplest stitching of things together. No matter what language you use, the end-results are indistinguishable.
 
  


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 this posible with iptables ? koye78 Linux - Networking 1 03-30-2006 01:09 PM
Is This Posible???? k1ll3r_x General 12 08-09-2005 04:59 PM
Question IS THIS POSIBLE craigvanham Linux - General 1 03-19-2004 05:03 AM
is it posible to install linux on a palm robodude Linux - Laptop and Netbook 1 02-03-2004 11:14 AM


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