LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Whats the difference between Linux and Ubuntu when it comes to bash scripting? (https://www.linuxquestions.org/questions/linux-newbie-8/whats-the-difference-between-linux-and-ubuntu-when-it-comes-to-bash-scripting-802368/)

sharee 04-16-2010 05:45 AM

Whats the difference between Linux and Ubuntu when it comes to bash scripting?
 
Is one better than the other? Bash scripting in Ubunu is something new for me and I kind of like it. Its similar to programming, in a sense. I have not had the opportunity to perform bash scripting in Linux. It seems like once you learn the commands and how too use them, it becomes easier to bash script.

troop 04-16-2010 05:47 AM

Ubuntu is Linux distribution. Linux is kernel.
bash is the same for any distro. shell scriptiong can be different for different shells.

cola 04-16-2010 06:08 AM

Quote:

Originally Posted by sharee (Post 3937419)
Is one better than the other? Bash scripting in Ubunu is something new for me and I kind of like it. Its similar to programming, in a sense. I have not had the opportunity to perform bash scripting in Linux. It seems like once you learn the commands and how too use them, it becomes easier to bash script.

google bash scripting tutorial.
Bash shell scripting is same on all linux distributions.

catkin 04-16-2010 06:59 AM

Quote:

Originally Posted by sharee (Post 3937419)
Is one better than the other? Bash scripting in Ubunu is something new for me and I kind of like it. Its similar to programming, in a sense. I have not had the opportunity to perform bash scripting in Linux. It seems like once you learn the commands and how too use them, it becomes easier to bash script.

Bash has its origins in the "command shell" -- a place outside the kernel (hence "shell") where users could enter commands, have them executed and the results displayed, in the same way as is done at the DOS prompt or the Windows command prompt (in case you are familiar with those). But bash has evolved from UNIX's command shells and UNIX's developers were, er, developers so they made a great tool, something more than a simple place to run commands. Being programmers they naturally gave it program-like capabilities including the genius idea -- a cornerstone of UNIX -- of "piplelining" command together so the output of one could be fed to the input of another and so on thus establishing the UNIX idea of single-purpose tools that could by strung together.

As UNIX/Linux shells have evolved they have gained more programming facilities and are now quite sophisticated in their own right -- functions, recursion, arrays, conditionals, string-manipulation, command output substitution ... and some once external commands have been built in for performance (test and echo are good examples) but bash can use all available commands in a more integrated way than other languages do with their "system" functions.

So yes -- bash scripting is very "similar to programming" and the more "you learn the commands and how too use them", the more you can do with bash scripts.

Beware bash' weaknesses though -- as always it's "horses for courses". Bash is slow at handling large strings and bash has to create a new process to run each external command which is quite slow and expensive in system resources.

EDIT:

Regards ubuntu/Linux, as has already been pointed out, ubuntu is a Linux-based product and bash is more-or-less identical wherever you find it. One difference not mentioned is that not all Linux-based "distros" have the same commands and, even if they do have the same commands, the format of output from those commands may be different. This makes it non-trivial to make "portable" bash scripts that can be run without change on a wide variety of systems.

onebuck 04-16-2010 07:42 AM

Hi,

Welcome to LQ!

'bash' is very useful to any user that really wants control of their system or perform maintenance on a UNIX or GNU/Linux system.

Quote:

excerpt from 'man bash';
NAME
bash - GNU Bourne-Again SHell
SYNOPSIS
bash [options] [file]
COPYRIGHT
Bash is Copyright (C) 1989-2004 by the Free Software Foundation, Inc.
DESCRIPTION
Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash also incorporates useful features from the Korn and C shells (ksh and csh).

Bash is intended to be a conformant implementation of the IEEE POSIX Shell and Tools specification (IEEE Working Group 1003.2).
You should look at a sample setup for .bashrc & .bash_profile for a user. This is a good way to control and streamline things for a user;

Code:

sample .bash_profile;

~$ cat .bash_profile

# .bash_profile
#08-30-06 12:21
#
# Source .bashrc
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

Code:

sample .bashrc;
:~$ cat .bashrc

#.bashrc
#08-30-06 12:20

# Add bin to path

export PATH="$PATH:/sbin:/usr/sbin:$HOME/bin"

#export PATH="$PATH:$HOME/bin"

# Dynamic resizing
shopt -s checkwinsize

# Custom prompt
#PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

#08-29-06 11:40

if [ `id -un` = root ]; then
  PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
 else
  PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
fi

#
# Add color
eval `dircolors -b`

# User defined aliases
alias cls='clear'
alias clls='clear; ls'
alias ll='ls -l'
alias lsa='ls -A'
alias lsg='ls | grep'
alias lsp='ls -1 /var/log/packages/ > package-list'
alias na='nano'
alias web='links -g -download-dir ~/ www.google.com'

#08-29-06 11:50

#To clean up and cover your tracks once you log off
#Depending on your version of BASH, you might have to use
# the other form of this command
  trap "rm -f ~$LOGNAME/.bash_history" 0

#The older KSH-style form
#  trap 0 rm -f ~$LOGNAME/.bash_history

The .bashrc is very useful! If you discern the above files you will be able to understand the strength and usefulness of bash.

Just a few useful links;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Bash Reference Manual <<<<<<< Great & Useful
Advanced Bash-Scripting Guide <<<<<<<< Very helpful
Linux Newbie Admin Guide
LinuxSelfHelp
Getting Started with Linux

The above links and others can be found at 'Slackware-Links' . More than just SlackwareŽ links!

MTK358 04-16-2010 07:49 AM

Quote:

Originally Posted by sharee (Post 3937419)
Is one better than the other? Bash scripting in Ubunu is something new for me and I kind of like it. Its similar to programming, in a sense. I have not had the opportunity to perform bash scripting in Linux. It seems like once you learn the commands and how too use them, it becomes easier to bash script.

ummm, Ubuntu is a Linux distro. Just like Fedora, Red Hat, Debian, arch, etc.


All times are GMT -5. The time now is 03:42 PM.