March 2010
M T W T F S S
« Feb    
1234567
891011121314
15161718192021
22232425262728
293031  
104

Categories

Archives

[one-liner]: Analyzing a System's BIOS from the Commandline under Fedora 10

Background

A system’s BIOS is a treasure trove of a lot of useful info about the capabilities of a computer. BIOS, which stands for Basic Input/Output System, contains information such as:

* motherboard manufacturer
* system’s serial number
* amount of RAM installed
* the CPUs speed & signature

Normally the BIOS is accessible by pressing the delete key or the F1 key.

Problem

Occasionally I’ve wanted to check out the BIOS settings of a system without having to go through the hassle of rebooting. With the help of this nifty command line tool, dmidecode, BIOS info can be had, without having to reboot.

Solution

dmidecode is a tool for dumping a computer’s DMI (some say SMBIOS) table contents in a human-readable format. This table contains a description of the system’s hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision. Thanks to this table, you can retrieve this information without having to probe for the actual hardware. While this is a good point in terms of report speed and safeness, this also makes the presented information possibly unreliable.

The DMI table doesn’t only describe what the system is currently made of, it also can report the possible evolutions (such as the fastest supported CPU or the maximal amount of memory supported).

SMBIOS stands for System Management BIOS, while DMI stands for Desktop Management Interface. Both standards are tightly related and developed by the DMTF (Desktop Manage- ment Task Force).

Example output from a Thinkpad T42 laptop

When you first run the dmidecode command it tells you a summary of how many structures are present within your system’s BIOS.

1
2
3
4
5
% dmidecode 
# dmidecode 2.9
SMBIOS 2.33 present.
61 structures occupying 2126 bytes.
Table at 0x000E0010.

Each structure is represented by a handle ID which is a hex value of the form 0×001F, followed by it’s type and it’s size.

System Info
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
57
58
59
60
61
...
 
Handle 0x0000, DMI type 0, 20 bytes
BIOS Information
	Vendor: IBM
	Version: 1RETDPWW (3.21 )
	Release Date: 06/02/2006
	Address: 0xDC000
	Runtime Size: 144 kB
	ROM Size: 1024 kB
	Characteristics:
		PCI is supported
		PC Card (PCMCIA) is supported
		PNP is supported
		APM is supported
		BIOS is upgradeable
		BIOS shadowing is allowed
		ESCD support is available
		Boot from CD is supported
		Selectable boot is supported
		EDD is supported
		3.5"/720 KB floppy services are supported (int 13h)
		Print screen service is supported (int 5h)
		8042 keyboard services are supported (int 9h)
		Serial services are supported (int 14h)
		Printer services are supported (int 17h)
		CGA/mono video services are supported (int 10h)
		ACPI is supported
		USB legacy is supported
		AGP is supported
		BIOS boot specification is supported
 
Handle 0x0001, DMI type 1, 25 bytes
System Information
	Manufacturer: IBM
	Product Name: 2373B09
	Version: ThinkPad T42
	Serial Number: 99N4BVC
	UUID: 205A7001-46D4-22CB-B51D-FDE5F7FCD3CD
	Wake-up Type: Power Switch
 
Handle 0x0002, DMI type 2, 8 bytes
Base Board Information
	Manufacturer: IBM
	Product Name: 2373B09
	Version: Not Available
	Serial Number: J1ZTY5031AP
 
Handle 0x0003, DMI type 3, 17 bytes
Chassis Information
	Manufacturer: IBM
	Type: Notebook
	Lock: Not Present
	Version: Not Available
	Serial Number: Not Available
	Asset Tag: No Asset Information
	Boot-up State: Unknown
	Power Supply State: Unknown
	Thermal State: Unknown
	Security Status: Unknown
	OEM Information: 0x00000000
CPU Info
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
...
 
Handle 0x0006, DMI type 4, 35 bytes
Processor Information
	Socket Designation: None
	Type: Central Processor
	Family: Pentium M
	Manufacturer: GenuineIntel
	ID: D6 06 00 00 BF B3 A3 AF
	Signature: Type 0, Family 6, Model 13, Stepping 6
	Flags:
		FPU (Floating-point unit on-chip)
		VME (Virtual mode extension)
		DE (Debugging extension)
		PSE (Page size extension)
		TSC (Time stamp counter)
		MSR (Model specific registers)
		MCE (Machine check exception)
		CX8 (CMPXCHG8 instruction supported)
		SEP (Fast system call)
		MTRR (Memory type range registers)
		PGE (Page global enable)
		MCA (Machine check architecture)
		CMOV (Conditional move instruction supported)
		PAT (Page attribute table)
		CLFSH (CLFLUSH instruction supported)
		DS (Debug store)
		ACPI (ACPI supported)
		MMX (MMX technology supported)
		FXSR (Fast floating-point save and restore)
		SSE (Streaming SIMD extensions)
		SSE2 (Streaming SIMD extensions 2)
		SS (Self-snoop)
		TM (Thermal monitor supported)
		PBE (Pending break enabled)
	Version: Intel(R) Pentium(R) M processor
	Voltage: 1.3 V
	External Clock: 400 MHz
	Max Speed: 1600 MHz
	Current Speed: 1600 MHz
	Status: Populated, Enabled
	Upgrade: None
	L1 Cache Handle: 0x000A
	L2 Cache Handle: 0x000B
	L3 Cache Handle: Not Provided
	Serial Number: Not Specified
	Asset Tag: Not Specified
	Part Number: Not Specified
...
RAM Info
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
...
Handle 0x0007, DMI type 5, 20 bytes
Memory Controller Information
	Error Detecting Method: None
	Error Correcting Capabilities:
		None
	Supported Interleave: One-way Interleave
	Current Interleave: One-way Interleave
	Maximum Memory Module Size: 1024 MB
	Maximum Total Memory Size: 2048 MB
	Supported Speeds:
		Other
	Supported Memory Types:
		DIMM
		SDRAM
	Memory Module Voltage: 2.9 V
	Associated Memory Slots: 2
		0x0008
		0x0009
	Enabled Error Correcting Capabilities:
		None
 
Handle 0x0008, DMI type 6, 12 bytes
Memory Module Information
	Socket Designation: DIMM Slot 1
	Bank Connections: 0 1
	Current Speed: Unknown
	Type: DIMM SDRAM
	Installed Size: 1024 MB (Double-bank Connection)
	Enabled Size: 1024 MB (Double-bank Connection)
	Error Status: OK
 
Handle 0x0009, DMI type 6, 12 bytes
Memory Module Information
	Socket Designation: DIMM Slot 2
	Bank Connections: 2 3
	Current Speed: Unknown
	Type: DIMM SDRAM
	Installed Size: 1024 MB (Double-bank Connection)
	Enabled Size: 1024 MB (Double-bank Connection)
	Error Status: OK
...
Cache Info
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
...
Handle 0x000A, DMI type 7, 19 bytes
Cache Information
	Socket Designation: Internal L1 Cache
	Configuration: Enabled, Socketed, Level 1
	Operational Mode: Write Back
	Location: Internal
	Installed Size: 32 KB
	Maximum Size: 32 KB
	Supported SRAM Types:
		Synchronous
	Installed SRAM Type: Synchronous
	Speed: Unknown
	Error Correction Type: Unknown
	System Type: Other
	Associativity: 8-way Set-associative
 
Handle 0x000B, DMI type 7, 19 bytes
Cache Information
	Socket Designation: Internal L2 Cache
	Configuration: Enabled, Socketed, Level 2
	Operational Mode: Write Back
	Location: Internal
	Installed Size: 2048 KB
	Maximum Size: 2048 KB
	Supported SRAM Types:
		Burst
	Installed SRAM Type: Burst
	Speed: Unknown
	Error Correction Type: Multi-bit ECC
	System Type: Unified
	Associativity: 8-way Set-associative
...
Port Info (USB, Infrared, Parallel, etc.)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
...
Handle 0x000D, DMI type 8, 9 bytes
Port Connector Information
	Internal Reference Designator: Not Available
	Internal Connector Type: None
	External Reference Designator: Infrared
	External Connector Type: Infrared
	Port Type: Other
 
Handle 0x000E, DMI type 8, 9 bytes
Port Connector Information
	Internal Reference Designator: Not Available
	Internal Connector Type: None
	External Reference Designator: Parallel
	External Connector Type: DB-25 female
	Port Type: Parallel Port ECP/EPP
 
Handle 0x000F, DMI type 8, 9 bytes
Port Connector Information
	Internal Reference Designator: Not Available
	Internal Connector Type: None
	External Reference Designator: External Monitor
	External Connector Type: DB-15 female
	Port Type: Video Port
 
Handle 0x0015, DMI type 8, 9 bytes
Port Connector Information
	Internal Reference Designator: Not Available
	Internal Connector Type: None
	External Reference Designator: Microphone Jack
	External Connector Type: Mini Jack (headphones)
	Port Type: Audio Port
 
Handle 0x0016, DMI type 8, 9 bytes
Port Connector Information
	Internal Reference Designator: Not Available
	Internal Connector Type: None
	External Reference Designator: Headphone Jack
	External Connector Type: Mini Jack (headphones)
	Port Type: Audio Port
 
Handle 0x0017, DMI type 8, 9 bytes
Port Connector Information
	Internal Reference Designator: Not Available
	Internal Connector Type: None
	External Reference Designator: S-Video-Out
	External Connector Type: Other
	Port Type: Video Port
 
Handle 0x0019, DMI type 8, 9 bytes
Port Connector Information
	Internal Reference Designator: Not Available
	Internal Connector Type: None
	External Reference Designator: Modem
	External Connector Type: RJ-11
	Port Type: Modem Port
 
Handle 0x001A, DMI type 8, 9 bytes
Port Connector Information
	Internal Reference Designator: Not Available
	Internal Connector Type: None
	External Reference Designator: Ethernet
	External Connector Type: RJ-45
	Port Type: Network Port
 
Handle 0x001B, DMI type 8, 9 bytes
Port Connector Information
	Internal Reference Designator: Not Available
	Internal Connector Type: None
	External Reference Designator: USB 1
	External Connector Type: Access Bus (USB)
	Port Type: USB
 
Handle 0x001C, DMI type 8, 9 bytes
Port Connector Information
	Internal Reference Designator: Not Available
	Internal Connector Type: None
	External Reference Designator: USB 2
	External Connector Type: Access Bus (USB)
	Port Type: USB
...
CardBus Slot Info
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
...
Handle 0x0022, DMI type 9, 13 bytes
System Slot Information
	Designation: CardBus Slot 1
	Type: 32-bit PC Card (PCMCIA)
	Current Usage: Available
	Length: Other
	ID: Adapter 0, Socket 0
	Characteristics:
		5.0 V is provided
		3.3 V is provided
		PC Card-16 is supported
		Cardbus is supported
		Zoom Video is supported
		Modem ring resume is supported
		PME signal is supported
		Hot-plug devices are supported
 
Handle 0x0023, DMI type 9, 13 bytes
System Slot Information
	Designation: CardBus Slot 2
	Type: 32-bit PC Card (PCMCIA)
	Current Usage: Available
	Length: Other
	ID: Adapter 1, Socket 0
	Characteristics:
		5.0 V is provided
		3.3 V is provided
		PC Card-16 is supported
		Cardbus is supported
		Zoom Video is supported
		Modem ring resume is supported
		PME signal is supported
		Hot-plug devices are supported
...
RAM Modules Info
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
...
Handle 0x002C, DMI type 16, 15 bytes
Physical Memory Array
	Location: System Board Or Motherboard
	Use: System Memory
	Error Correction Type: None
	Maximum Capacity: 1 GB
	Error Information Handle: Not Provided
	Number Of Devices: 2
 
Handle 0x002D, DMI type 17, 27 bytes
Memory Device
	Array Handle: 0x002C
	Error Information Handle: No Error
	Total Width: 64 bits
	Data Width: 64 bits
	Size: 1024 MB
	Form Factor: SODIMM
	Set: None
	Locator: DIMM 1
	Bank Locator: Bank 0/1
	Type: DDR
	Type Detail: Synchronous
	Speed: Unknown
	Manufacturer: Not Specified
	Serial Number: Not Specified
	Asset Tag: Not Specified
	Part Number: Not Specified
 
Handle 0x002E, DMI type 17, 27 bytes
Memory Device
	Array Handle: 0x002C
	Error Information Handle: No Error
	Total Width: 64 bits
	Data Width: 64 bits
	Size: 1024 MB
	Form Factor: SODIMM
	Set: None
	Locator: DIMM 2
	Bank Locator: Bank 2/3
	Type: DDR
	Type Detail: Synchronous
	Speed: Unknown
	Manufacturer: Not Specified
	Serial Number: Not Specified
	Asset Tag: Not Specified
	Part Number: Not Specified
 
Handle 0x002F, DMI type 18, 23 bytes
32-bit Memory Error Information
	Type: OK
	Granularity: Unknown
	Operation: Unknown
	Vendor Syndrome: Unknown
	Memory Array Address: Unknown
	Device Address: Unknown
	Resolution: Unknown
 
Handle 0x0030, DMI type 19, 15 bytes
Memory Array Mapped Address
	Starting Address: 0x00000000000
	Ending Address: 0x0007FFFFFFF
	Range Size: 2 GB
	Physical Array Handle: 0x002C
	Partition Width: 0
 
Handle 0x0031, DMI type 20, 19 bytes
Memory Device Mapped Address
	Starting Address: 0x00000000000
	Ending Address: 0x0003FFFFFFF
	Range Size: 1 GB
	Physical Device Handle: 0x002D
	Memory Array Mapped Address Handle: 0x0030
	Partition Row Position: 1
 
Handle 0x0032, DMI type 20, 19 bytes
Memory Device Mapped Address
	Starting Address: 0x00040000000
	Ending Address: 0x0007FFFFFFF
	Range Size: 1 GB
	Physical Device Handle: 0x002E
	Memory Array Mapped Address Handle: 0x0030
	Partition Row Position: 1
...
Pointing Device Info
1
2
3
4
5
6
7
8
9
10
11
12
13
...
Handle 0x0033, DMI type 21, 7 bytes
Built-in Pointing Device
	Type: Track Point
	Interface: PS/2
	Buttons: 3
 
Handle 0x0034, DMI type 21, 7 bytes
Built-in Pointing Device
	Type: Touch Pad
	Interface: PS/2
	Buttons: 0
...
The End
1
2
...
End Of Table

There are some additional handles related to system logging, hardware security, and OEM information that I ommited to keep this post from just becoming a complete dump of the output but needless to say dmidecode is a pretty exhaustive and sweet command.

Check out the dmidecode website or the man page for more information.

Broken Arrow Keys during an Ubuntu 9.04 install on Vmware Server 1.X

Background

Recently I was trying to create a Ubuntu 9.04 vmware image using Vmware Server 1.08, but I was doing it remotely from my Fedora 10 laptop which was running Vmware Server 1.06. This can normally be done by using Vmware Server’s ability to remotely connect to other Vmware Servers.

VMware Server Console

Here’s my work flow. NOTE: Ubuntu 9.04 will be running on the vmware server on CentOS 5.4.

VMware Workflow

Problem

While going through the setup I encountered a problem I hadn’t seen before where the arrow keys didn’t appear to be working within GRUB while I was installing Ubuntu 9.04.

broken arrow keys

Solution

Turns out there is an option you can enable (i.e. set to TRUE) in the $HOME/.vmware/preferences file which fixes this.

1
xkeymap.nokeycodeMap = "TRUE"

NOTE: This change was made to the Vmware Server that was running on the Fedora 10 box.


…. Continue reading → Broken Arrow Keys during an Ubuntu 9.04 install on Vmware Server 1.X »»

[one-liner]: Previewing a Pretty Printed Text File using enscript & ps2pdf

Background

Before my wife and I had kids we thought it would be nice to collect the United States quarters that were released during 1999 through 2008 to commemorate each of the 50 states. Seemed like something simple to do and would be a nice gift for the kids when they got older. So we bought a couple of the blue books which you can fill up with quarters as you find them. Each book contains 100 slots, 2 for each state. One slot is for the Philadelphia minted version of the quarter, and the other slot is for the Denver mint.

Problem

Well we ended up having 3 kids so we have to collect 300 quarters. The task of finding the quarters has been more of a dad task so when I have a chance, I’ll put a $5 dollar bill in various soda machines at work and go quarter fishing. This approach has been working fairly well and we’ve collected ~130 of the 300 quarters thus far.

However I’ve started getting to the point where I’m netting a lot of duplicates and the job of having to bring them home to weed through them is starting to get old. Having a list of which quarters we already have would sure be nice, so I could quickly nix any duplicates.

Solution

Of course I wanted a low tech solution, i.e. a piece of paper in my wallet would do the job, but how to do it?

The answer? A text file that I could maintain would suffice. No need for a bloated spreadsheet or some fancy handheld app. So I created a file, quarters.txt, like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
State           Year  Cnt (P/D)
=====           ====  =========
Alabama         2003  2/1
Alaska          2008  3/1
Arizona         2008  3/0
Arkansas        2003  3/0
California      2005  3/0
Colorado        2006  3/0
Connecticut     1999  3/2
Delaware        1999  0/0
Florida         2004  2/0
Georgia         1999  2/1
Hawaii          2008  3/0
...

It’s about as simple a text file as you can get. 3 columns, State, Year, and Counts. The 3rd column shows how many P and D quarters I have for a given state. So for example, for Alabama, I’ve got 2 Philadelphia minted quarters, and 1 Denver minted.

So you’re probably wondering, “why the hell is this guy writing up this in a blog post?”

We’ll the interesting bit to this low tech solution is how I print this list out. For this task I make use of a pretty powerful UNIX command called enscript, which lets you do all kinds of nifty things to a text file to augment how it looks when it gets printed.

About the only thing enscript doesn’t do for you, is give you the ability to preview your text file prior to printing. To accomplish this bit, I made use of another powerful UNIX command called ps2pdf. This command will take a postscript file (ps) and convert it to a pdf file.

So putting all the pieces together I came up with the following command:

1
enscript --fancy-header -U 4 quarters.txt -o - | ps2pdf - quarters_sm.pdf

The first part of this command, will call enscript instructing it to convert the file quarters.txt, and print it to standard out -o -. The printout will include some fancy headers and enscript will print the text file out in what is called 4 UP. This means that 4 pages will be printed on a single piece of paper. You could also print the page out in 2 UP, 8 UP, etc. It only needs to be a power of 2. BTW, 2 and 4 are the most commonly used, 8 is pretty hard to read.

The second part of this command passes the postscript generated by enscript through a UNIX pipe which gets picked up by ps2pdf, and converts it into a PDF file, quarters_sm.pdf.

From here you can check what the page would look like using your favorite PDF viewer, such as evince or xpdf. Once you’re comfortable with the page you can actually print it out from the PDF reader, or via the command-line.


…. Continue reading → [one-liner]: Previewing a Pretty Printed Text File using enscript & ps2pdf »»

[one-liner]: Copying & Moving Files efficiently with xargs

Background

From time to time I need to move and/or copy a subset of files from one directory to another. I typically would use something like one of these to do the task:

1
2
3
4
5
#-- COPY
find . -type f -ctime -1 | xargs -I {} cp {} /some/other/directory
 
#-- MOVE
find . -type f -ctime -1 | xargs -I {} mv {} /some/other/directory

NOTE: The 1st command finds all the files in the current directory that are less than 24 hours old, and copies them to /some/other/directory. The 2nd command finds all the files in the current directory that are less than 24 hours old, and moves them to /some/other/directory.

But then I realized that by using xargs’ –I switch I was basically limiting xargs to doing a single file at a time. According to xargs’ man page, when you use the –I switch you’re implying the –x switch AND the –L 1 switch. The L switch is what tells xargs how many lines of input to process at a time, so we’re basically telling it to only handle one file at a time. This made no sense. I was unintentially limiting xargs’ ability to optimize the command-line. So I found a better way.

New Approach

By utilizing 2 little used switches (–t | ––target-directory) on cp and mv I could un-tie xargs’ hands.

copy
1
2
3
4
5
# long form
find . -type f -ctime -1 | xargs -0 cp --target-directory=/some/other/directory
 
# short form
find . -type f -ctime -1 | xargs -0 cp -t /some/other/directory
move
1
2
3
4
5
# long form
find . -type f -ctime -1 | xargs -0 mv --target-directory=/some/other/directory
 
# short form
find . -type f -ctime -1 | xargs -0 mv -t /some/other/directory

NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.

[one-liner]: Getting Remote Desktop Sharing & Compiz to play nice under Ubuntu 9.04 with GNOME

Background

This one threw me for a bit but I finally realized that when I had Compiz enabled on an Ubuntu 9.04 system, I couldn’t use VNC to connect via Remote Desktop Sharing in GNOME (aka. Vino, aka. VNC Server). Apparently this has been an issue going back since 2007 8-(, when Compiz is enabled. Since this is the first system that I actually bothered to enable Compiz I’m dealing with it for the first time.

The problem shows up when you try and connect remotely to a system that has Remote Desktop Sharing enabled –AND– Compiz. This thread on launchpad was helpful in showing the lineage of the problem, and the only real workaround to get Remote Desktop Sharing to work.

Solution

The workaround? If you’re coming at it remotely, and are too lazy to walk over to the remote system … ssh into the remote system and run these commands to effectively disable Compiz, and enable (re-enable?) the window manager Metacity.

1
2
3
ssh <remote system>
export DISPLAY=:0
nohup metacity --replace > /dev/null &

NOTE: I’m wrapping a “nohup … > /dev/null &” around the “metacity –replace” so that when/if I close the ssh connection, the metacity running in there doesn’t get inexplicably killed off. Additionally, this version of nohup (/usr/bin/nohup), likes to leave a nohup.out file lying around, which is just cruft in our case, so by sending all the output to /dev/null we are effectively disabling the creation of the nohup.out file.

Now you can do your work remotely with Compiz turned off. But now what to do when you’re all done and you want to turn Compiz back on? Easy. Do this:

1
2
3
ssh <remote system>
export DISPLAY=:0
nohup compiz --replace > /dev/null &

Useful Links

NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.

[one-liner]: How to Use the Bash Shell’s export Command

Problem

Recently at my day job I’ve been having to go through some pretty old Bash scripts that I’ve basically inherited. As I’ve been going through them I’ve been seeing a lot of confusion as to the proper use of Bash’s export command. The major offense? Not really understand whether a particular variables needs to be exported, or not. So I thought I’d take a moment just to clarify when and when not to use export.

The export command has really only one true purpose. To mark and/or unmark variables (and functions) that you want to have automatically exported to environments of subsequently executed commands. So if you create a script that calls other commands, and you want to push variables into the environment of these commands, then you’ll want to use export.

Example #1 (without export)

For example, let’s say we have the following 2 scripts:

1
2
3
4
5
6
7
#!/bin/bash
# script #1: parent.bash
 
var1="this was set by the parent shell script"
echo "inside $0 script: $var1"
 
./child.bash
1
2
3
4
#!/bin/bash
# script #2: child.bash
 
echo "inside $0 script: $var1"

And when I run the script parent.bash I get this output:

1
2
3
4
5
# output from parent.bash & child.bash (without export)
 
% ./parent.bash
inside ./parent.bash script: this was set by the parent shell script
inside ./child.bash script:

Notice how the variable $var1, which was set in the parent.bash script, didn’t get displayed by the child.bash script? Now watch this example with the variable $var1 exported in the parent.bash script.

Example #2 (with export)

1
2
3
4
5
6
7
#!/bin/bash
# script #1: parent.bash
 
export var1="this was set by the parent shell script"
echo "inside $0 script: $var1"
 
./child.bash
1
2
3
4
#!/bin/bash
# script #2: child.bash
 
echo "inside $0 script: $var1"

And when we run parent.bash

1
2
3
4
5
# output from parent.bash & child.bash (with export)
 
% ./parent.bash
inside ./parent.bash script: this was set my the parent shell script
inside ./child.bash script: this was set my the parent shell script

Example #3 (un-exporting)

Export isn’t just a one trick pony. It can also unmark a previously exported variable.


…. Continue reading → [one-liner]: How to Use the Bash Shell’s export Command »»

Page 1 of 1012345...Last »