Results 1 to 6 of 6

Thread: Creating array with Bash shell

  1. #1
    Join Date
    Oct 2009
    Posts
    82

    Creating array with Bash shell

    Hello sir ,

    I am newbie in the linux programming and need some guidence regarding creation and implementation of array in Linux.The basic things I don't know.How would I implement in a large application and whenever I required to put some different command to system through the script then How would I do.

    Thanks and regards
    C. Pammela

  2. #2
    Join Date
    Nov 2005
    Posts
    3,026

    Creating array with Bash shell

    Creating array with Bash shell :

    The array is very useful user defined data type which represent a number of variable of same data type.To create a array in Linux on bash shell wold be as follows:

    array_var=(Apple mango banana fare magenta)
    len=${#array[*]}
    echo "The array has $len members. They are:"
    i=0
    while [ $i -lt $len ]; do
    echo "$i: ${array[$i]}"
    let i++
    done


    The len variable will represent the number of values in array and the loop will round till it completes the name of the members.

  3. #3
    Join Date
    May 2008
    Posts
    2,680

    Defining variable with Bash shell

    Defining variable with Bash shell :

    The Declaration of variable for bash shell is quite simple,The variable is doesn't depends on the type,whatever value you will accepted by the variable.I am going to show you an example which will show the declaration of the variable :


    Var=1
    while [ $n -le 6 ]; do
    echo $n
    let n++
    done


    Use this given code above to create a variable.The variable is declared named var and an integer value is assigned in the variable.While loop is being used to execute find the increased value of 1 at 6 times.

  4. #4
    Dr. V Guest

    Executing a program with Bash shell

    Executing a program with Bash shell :

    When you would be prepare to create a program you need a platform for creation and you can choose the notepad or any editor like :Vi or nano.

    After creating you need to save it with .sh extension as a post fix of the file.To execute the file of bash.It is necessary to know on which shell you are working currently and follow the below code to execute a bash script.

    The user script are always stored in the home directory of user and the user can use the ./ method to locate the home directory of a user.

    $ ./myscript.sh

    The ./ shows the current home directory of the user.

  5. #5
    Join Date
    Jan 2008
    Posts
    3,388

    Searching and Replacing Substrings within Strings

    Searching and Replacing Substrings within Strings :


    Using this method you can replace one or more collection of string.The syntax is displayed here :

    alpha="The youngsters are growing with \"Technology\" is replaced."
    beta="${alpha/Technology/New Ideas}"


    The beta variable contains some variables but after execution of this statement the Technology word would be changed into New ideas.
    To replace all cases,you can // (Double hyphen) mark to initiate the changes
    beta="${alpha//Technology/New Ideas}"

  6. #6
    Join Date
    May 2008
    Posts
    4,085

    Useful string operations in bash shell

    Useful string operations in bash shell :

    You can perform better operations with the strings operations within your script files.This concept can be used to write a long and useful script :

    I am going to introduce with four operators in the scripting with bash shell :

    Operator "#" - To delete the pair of words from the left of sentence
    Operator "##" - To delete the two pairs of words from the left of sentence
    Operator "%". - To delete the pair of words from the right of sentence
    Operator "%%" - To delete the two pair of words from the right of sentence

    These operators is being used to operate the string manipulations .

Similar Threads

  1. Bash script for creating a new month and year
    By Kohlmann in forum Software Development
    Replies: 4
    Last Post: 30-08-2010, 09:09 PM
  2. Creating shell script in ubuntu
    By Elizabeth Allen in forum Operating Systems
    Replies: 5
    Last Post: 24-03-2010, 01:35 PM
  3. Eval in bash shell
    By Carnie in forum Software Development
    Replies: 4
    Last Post: 12-03-2010, 09:52 PM
  4. Problem in creating array from string values
    By Cedric in forum Software Development
    Replies: 4
    Last Post: 19-01-2010, 05:48 PM
  5. Creating an array from a class
    By Kingfisher in forum Software Development
    Replies: 3
    Last Post: 25-11-2009, 02:50 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,046,488.80723 seconds with 16 queries