Results 1 to 8 of 8

Thread: Shell Script for Searching a String

  1. #1
    Junior Member
    Join Date
    Sep 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Shell Script for Searching a String

    Hello

    I want to get the value of extension_dir from php.ini

    grep -i /usr/local/lib/php/extensions /usr/local/lib/php.ini

    This returns

    extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"


    I just want

    /usr/local/lib/php/extensions/no-debug-non-zts-20060613


    only.

    My question is

    How can I search for that and extract it?
    I also need to assign it to a vairable

    Thanks

  2. #2
    Junior Member
    Join Date
    Sep 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Code:
    #!/bin/bash
    for  var1 in `cut -f 2 -d "="  /usr/local/lib/php.ini `
    do
    
       echo $var1
    done

    This is returning all values, but I want extension_dir only

  3. #3
    Administrator
    Join Date
    Apr 2007
    Posts
    25
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rep Power
    10

    Default

    Try
    Code:
     grep -i /usr/local/lib/php/extensions /usr/local/lib/php.ini | cut -d'=' -f2

  4. #4
    Junior Member
    Join Date
    Sep 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Thank you

    root@core2quad2 [~]# grep -i /usr/local/lib/php/extensions /usr/local/lib/php.ini | cut -d'=' -f2
    "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"
    root@core2quad2 [~]#



    It is displaying the correct value.

    One more question
    How can I assign this value to a variable ?

    Code:
    PATH=grep -i /usr/local/lib/php/extensions /usr/local/lib/php.ini | cut -d'=' -f2
    echo $PATH
    wont display the result, but it will just display
    grep -i /usr/local/lib/php/extensions /usr/local/lib/php.ini | cut -d'=' -f2

  5. #5
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,512
    Thanks
    17
    Thanked 799 Times in 511 Posts
    Rep Power
    10

    Default

    Code:
    VAR=$(grep -i /usr/local/lib/php/extensions /usr/local/lib/php.ini | cut -d'=' -f2)
    echo $VAR
    export PATH=$PATH:$VAR
    echo $PATH
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  6. #6
    Junior Member
    Join Date
    Sep 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Quote Originally Posted by nixcraft View Post
    Code:
    VAR=$(grep -i /usr/local/lib/php/extensions /usr/local/lib/php.ini | cut -d'=' -f2)
    echo $VAR
    export PATH=$PATH:$VAR
    echo $PATH

    Thank you

    I have one more problem



    Code:
    VAR=$(grep -i /usr/local/lib/php/extensions /usr/local/lib/php.ini | cut -d'=' -f2)
    echo "Extension Folder is "  $VAR
    wget www.mysite.com/loaders.zip
    unzip loaders.zip
    mv * $VAR

    But here it gives

    mv: target `"/usr/local/lib/php/extensions/no-debug-non-zts-20060613"' is not a directory


    I assumge, I need to remove the " " from the starting and ending.

    How can I do that ?

  7. #7
    Junior Member
    Join Date
    Sep 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    I found this is what I need

    VAR=$(grep -i /usr/local/lib/php/extensions /usr/local/lib/php.ini | cut -d'=' -f2)
    echo "Extension Folder is "
    echo "$VAR" | tr '"' ' '


    Just wanted to know, how can I assign the output of the last echo command to another variable ?

  8. #8
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,512
    Thanks
    17
    Thanked 799 Times in 511 Posts
    Rep Power
    10

    Default

    Quote Originally Posted by vivekv View Post
    I found this is what I need

    VAR=$(grep -i /usr/local/lib/php/extensions /usr/local/lib/php.ini | cut -d'=' -f2)
    echo "Extension Folder is "
    echo "$VAR" | tr '"' ' '


    Just wanted to know, how can I assign the output of the last echo command to another variable ?
    Try...
    Code:
    VAR=$(grep -i /usr/local/lib/php/extensions /usr/local/lib/php.ini | cut -d'=' -f2)
    echo "Extension Folder is $VAR"
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. split files by specifying a string (bash shell)
    By vikas027 in forum Shell scripting
    Replies: 7
    Last Post: 21st June 2010, 12:35 PM
  2. Binary Conversion Of Shell Script (shell script compiler)
    By chandanperl in forum Shell scripting
    Replies: 3
    Last Post: 29th July 2008, 10:22 AM
  3. Shell Script Searching For a Record In The File
    By vinz4ever in forum Shell scripting
    Replies: 1
    Last Post: 11th May 2008, 07:35 PM
  4. example for string connect to a command.
    By ryan in forum Shell scripting
    Replies: 2
    Last Post: 22nd February 2005, 01:05 PM
  5. searching for bad words script
    By marinm in forum Shell scripting
    Replies: 1
    Last Post: 3rd February 2005, 04:32 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •