nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Shell Script for Searching a String

This is a discussion on Shell Script for Searching a String within the Shell scripting forums, part of the Development/Scripting category; 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" ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-03-2009, 12:33 AM
Junior Member
User
 
Join Date: Sep 2007
OS: CentOS
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
vivekv is on a distinguished road
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
Reply With Quote
  #2 (permalink)  
Old 09-03-2009, 01:10 AM
Junior Member
User
 
Join Date: Sep 2007
OS: CentOS
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
vivekv is on a distinguished road
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
Reply With Quote
  #3 (permalink)  
Old 09-03-2009, 01:42 PM
Administrator
User
 
Join Date: Apr 2007
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Rep Power: 10
root has disabled reputation
Default

Try
Code:
 grep -i /usr/local/lib/php/extensions /usr/local/lib/php.ini | cut -d'=' -f2
Reply With Quote
  #4 (permalink)  
Old 09-03-2009, 01:48 PM
Junior Member
User
 
Join Date: Sep 2007
OS: CentOS
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
vivekv is on a distinguished road
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
Reply With Quote
  #5 (permalink)  
Old 09-03-2009, 04:26 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
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
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #6 (permalink)  
Old 10-03-2009, 12:00 AM
Junior Member
User
 
Join Date: Sep 2007
OS: CentOS
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
vivekv is on a distinguished road
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 ?
Reply With Quote
  #7 (permalink)  
Old 10-03-2009, 12:24 AM
Junior Member
User
 
Join Date: Sep 2007
OS: CentOS
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
vivekv is on a distinguished road
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 ?
Reply With Quote
  #8 (permalink)  
Old 10-03-2009, 03:18 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
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"
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply

Tags
cut , grep , php , php.ini , shell scripting , string


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Binary Conversion Of Shell Script (shell script compiler) chandanperl Shell scripting 3 29-07-2008 10:22 AM
Shell Script Searching For a Record In The File vinz4ever Shell scripting 1 11-05-2008 07:35 PM
split files by specifying a string (bash shell) vikas027 Shell scripting 4 01-11-2007 04:22 PM
example for string connect to a command. ryan Shell scripting 2 22-02-2005 01:05 PM
searching for bad words script marinm Shell scripting 1 03-02-2005 04:32 PM


All times are GMT +5.5. The time now is 08:57 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38