[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

10/30/2009 at 08:20AM PDT, ID: 24858319
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Store command output into variable

Asked by kickenchicken57 in Bourne-Again Shell (bash), Linux Programming, Fedora Linux

Tags: linux, bash, shell, fedora

I am new to bash scripting and linux. I have a bash script that I have been working on that will take a path to a dd disk image file and pass it into fdisk to parse out some information. The issue that I am having is after I use sed to get the text that I want, I can't figure out how to save it into a variable. Instead I just keep getting an error:

 "/bin/timeline: line 49: /media/USB: No such file or directory"

This error appears to originate from the line where I set the temp variable:

temp=`$line|sed "s/.*\.001p[[:digit:]][^[:digit:]]\{0,\}\([[:digit:]]\{1,\}\).*/\1/"`

I have tried surrounding the command in bacticks like above and with $() but I still get the same error message. Below is what the output looks like from running the command:

[root@SIFTWorkstation /]# timeline /media/USB\ 500GB/Images/6RX99BCP/6RX99BCP.001
-------------------------------------------
/media/USB 500GB/Images/6RX99BCP/6RX99BCP.001p1   *          63   109980989    54990463+   7  HPFS/NTFS
-------------------------------------------
63
/bin/timeline: line 49: /media/USB: No such file or directory
count = 1
-------------------------------------------
/media/USB 500GB/Images/6RX99BCP/6RX99BCP.001p2       109980990   156296384    23157697+   7  HPFS/NTFS
-------------------------------------------
109980990
/bin/timeline: line 49: /media/USB: No such file or directory
count = 2
partition_offsets[0] = 1
temp =
[root@SIFTWorkstation /]#
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:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
#!/bin/bash
 
#Check that there is one argument passed in
 
if [ $# -ne 1 ]
then
	echo "Usage: $(basename "$0") path"
	echo "  path: path to the image file"	
	exit 1
fi
 
 
 
#Check that the image file exists
 
if [ ! -f "$1" ]
then
	echo "File: "$1" does not exist"
	exit 1
fi
 
 
 
#Grab the basename of the file
 
filename=$(basename "$1")
#echo "Filename: $filename"
 
 
 
#Store the file name without the extension as the case name
 
casenum=`echo $filename | sed "s/\..*//"`
#echo "Case number = $casenum"
 
 
 
#Get the details about the disk image
 
declare -a partition_offsets
partition_offsets[0]=1
count=0
fdisk -ul "$1" 2>/dev/null | grep "6RX99BCP\.001p" | while read line
do
	echo "-------------------------------------------"
	echo "$line"
	echo "-------------------------------------------"
	echo $line | sed "s/.*\.001p[[:digit:]][^[:digit:]]\{0,\}\([[:digit:]]\{1,\}\).*/\1/"
	temp=`$line|sed "s/.*\.001p[[:digit:]][^[:digit:]]\{0,\}\([[:digit:]]\{1,\}\).*/\1/"`
	count=$[$count + 1]
	echo "count = $count"
done
 
echo -n "partition_offsets[0] = "
echo ${partition_offsets[0]}
echo "temp = $temp"
[+][-]10/30/09 08:25 AM, ID: 25703896

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Bourne-Again Shell (bash), Linux Programming, Fedora Linux
Tags: linux, bash, shell, fedora
Sign Up Now!
Solution Provided By: amit_g
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10/30/09 08:34 AM, ID: 25703984

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/30/09 08:39 AM, ID: 25704022

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 08:50 AM, ID: 25704141

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/30/09 10:13 AM, ID: 25704992

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 12:42 PM, ID: 25706187

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/30/09 01:00 PM, ID: 25706319

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/01/09 04:09 AM, ID: 25713450

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11/02/09 06:30 AM, ID: 25719586

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/02/09 01:08 PM, ID: 25723745

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 09:43 AM, ID: 25731463

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74 - Hierarchy / EE_QW_3_20080625