New Posts  All Forums:Forum Nav:

Bash Script +=

post #1 of 8
Thread Starter 
Just as the title says is there a way to do a += on a string? I have a global variable called list that I would like to contain all the values that a user enters. I use a function to get the input which has a local variable called temp that actually stores the single value. I want to do something like $list += $temp + '\
' at the bottom of the function.
Edited by kschat - 4/26/11 at 11:33pm
baby cakes
(13 items)
 
Macbook 4,1
(13 items)
 
 
CPUMotherboardGraphicsRAM
i7 930 [4.01Ghz vCore 1.28125 HT on] GA-X58A-UD3R ZOTAC GTX 460 1GB SLI [840/1680/1900 @stock volts] CORSAIR XMS3 6GB (3 x 2GB) 1600Mhz 
Hard DriveOptical DriveOSMonitor
C300 64GB SATA III, 2x F3 1TB 7200rpm RAID 0 Sony Optiarc 24X DVD/CD Ubuntu 14.04 22" Dell SP2009W 1680x1050 
PowerCase
CORSAIR HX 750W Cooler Master HAF 922 
CPUMotherboardGraphicsRAM
Core 2 Duo 2.4Ghz Penryn T8300 Some logical board GMA X3100 4GB (2x2GB) DDR2 667Mhz 
Hard DriveOptical DriveOSMonitor
Hitachi 160 GB 5400 RPM SATA II Combo drive OSX 10.6.4 (Snow leopard) 13.3" 1280x800 TFT 
PowerCase
Dying battery White macbook case 
  hide details  
Reply
baby cakes
(13 items)
 
Macbook 4,1
(13 items)
 
 
CPUMotherboardGraphicsRAM
i7 930 [4.01Ghz vCore 1.28125 HT on] GA-X58A-UD3R ZOTAC GTX 460 1GB SLI [840/1680/1900 @stock volts] CORSAIR XMS3 6GB (3 x 2GB) 1600Mhz 
Hard DriveOptical DriveOSMonitor
C300 64GB SATA III, 2x F3 1TB 7200rpm RAID 0 Sony Optiarc 24X DVD/CD Ubuntu 14.04 22" Dell SP2009W 1680x1050 
PowerCase
CORSAIR HX 750W Cooler Master HAF 922 
CPUMotherboardGraphicsRAM
Core 2 Duo 2.4Ghz Penryn T8300 Some logical board GMA X3100 4GB (2x2GB) DDR2 667Mhz 
Hard DriveOptical DriveOSMonitor
Hitachi 160 GB 5400 RPM SATA II Combo drive OSX 10.6.4 (Snow leopard) 13.3" 1280x800 TFT 
PowerCase
Dying battery White macbook case 
  hide details  
Reply
post #2 of 8
Exactly what do you mean by B-Script? I've never heard of it, and a search turns up nothing definitive.
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
post #3 of 8
Thread Starter 
Bash Script, sorry short hand (programmer at heart I guess )
baby cakes
(13 items)
 
Macbook 4,1
(13 items)
 
 
CPUMotherboardGraphicsRAM
i7 930 [4.01Ghz vCore 1.28125 HT on] GA-X58A-UD3R ZOTAC GTX 460 1GB SLI [840/1680/1900 @stock volts] CORSAIR XMS3 6GB (3 x 2GB) 1600Mhz 
Hard DriveOptical DriveOSMonitor
C300 64GB SATA III, 2x F3 1TB 7200rpm RAID 0 Sony Optiarc 24X DVD/CD Ubuntu 14.04 22" Dell SP2009W 1680x1050 
PowerCase
CORSAIR HX 750W Cooler Master HAF 922 
CPUMotherboardGraphicsRAM
Core 2 Duo 2.4Ghz Penryn T8300 Some logical board GMA X3100 4GB (2x2GB) DDR2 667Mhz 
Hard DriveOptical DriveOSMonitor
Hitachi 160 GB 5400 RPM SATA II Combo drive OSX 10.6.4 (Snow leopard) 13.3" 1280x800 TFT 
PowerCase
Dying battery White macbook case 
  hide details  
Reply
baby cakes
(13 items)
 
Macbook 4,1
(13 items)
 
 
CPUMotherboardGraphicsRAM
i7 930 [4.01Ghz vCore 1.28125 HT on] GA-X58A-UD3R ZOTAC GTX 460 1GB SLI [840/1680/1900 @stock volts] CORSAIR XMS3 6GB (3 x 2GB) 1600Mhz 
Hard DriveOptical DriveOSMonitor
C300 64GB SATA III, 2x F3 1TB 7200rpm RAID 0 Sony Optiarc 24X DVD/CD Ubuntu 14.04 22" Dell SP2009W 1680x1050 
PowerCase
CORSAIR HX 750W Cooler Master HAF 922 
CPUMotherboardGraphicsRAM
Core 2 Duo 2.4Ghz Penryn T8300 Some logical board GMA X3100 4GB (2x2GB) DDR2 667Mhz 
Hard DriveOptical DriveOSMonitor
Hitachi 160 GB 5400 RPM SATA II Combo drive OSX 10.6.4 (Snow leopard) 13.3" 1280x800 TFT 
PowerCase
Dying battery White macbook case 
  hide details  
Reply
post #4 of 8
list=$list$some_user_input_var
Akiyama Mio
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6420 @ stock, 0.98v Asus P5N-E SLI Gainward GTX 460 1GB @ 800/1600/1900 2x2GB Kingston @ 800MHz 5-5-5-15 2T 
Hard DriveOptical DriveOSMonitor
WD 250GB, 320GB SATA/3, 16MB Cache, Seagate 1TB LG GSA-H62N 18x SATA Ubuntu 9.10 x86 & Win7 x86 Asus VW222U 
KeyboardPowerCase
Logitech Classic Corsair 650HX NZXT Apollo Black 
  hide details  
Reply
Akiyama Mio
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6420 @ stock, 0.98v Asus P5N-E SLI Gainward GTX 460 1GB @ 800/1600/1900 2x2GB Kingston @ 800MHz 5-5-5-15 2T 
Hard DriveOptical DriveOSMonitor
WD 250GB, 320GB SATA/3, 16MB Cache, Seagate 1TB LG GSA-H62N 18x SATA Ubuntu 9.10 x86 & Win7 x86 Asus VW222U 
KeyboardPowerCase
Logitech Classic Corsair 650HX NZXT Apollo Black 
  hide details  
Reply
post #5 of 8
Thread Starter 
Ahh thank you that worked! I still have on small problem though, I also want to append a null terminator to the end of list=$list$temp but when I try list=$list$temp\
it just appends an n on the end and not a null terminator. I also tried '\
'
baby cakes
(13 items)
 
Macbook 4,1
(13 items)
 
 
CPUMotherboardGraphicsRAM
i7 930 [4.01Ghz vCore 1.28125 HT on] GA-X58A-UD3R ZOTAC GTX 460 1GB SLI [840/1680/1900 @stock volts] CORSAIR XMS3 6GB (3 x 2GB) 1600Mhz 
Hard DriveOptical DriveOSMonitor
C300 64GB SATA III, 2x F3 1TB 7200rpm RAID 0 Sony Optiarc 24X DVD/CD Ubuntu 14.04 22" Dell SP2009W 1680x1050 
PowerCase
CORSAIR HX 750W Cooler Master HAF 922 
CPUMotherboardGraphicsRAM
Core 2 Duo 2.4Ghz Penryn T8300 Some logical board GMA X3100 4GB (2x2GB) DDR2 667Mhz 
Hard DriveOptical DriveOSMonitor
Hitachi 160 GB 5400 RPM SATA II Combo drive OSX 10.6.4 (Snow leopard) 13.3" 1280x800 TFT 
PowerCase
Dying battery White macbook case 
  hide details  
Reply
baby cakes
(13 items)
 
Macbook 4,1
(13 items)
 
 
CPUMotherboardGraphicsRAM
i7 930 [4.01Ghz vCore 1.28125 HT on] GA-X58A-UD3R ZOTAC GTX 460 1GB SLI [840/1680/1900 @stock volts] CORSAIR XMS3 6GB (3 x 2GB) 1600Mhz 
Hard DriveOptical DriveOSMonitor
C300 64GB SATA III, 2x F3 1TB 7200rpm RAID 0 Sony Optiarc 24X DVD/CD Ubuntu 14.04 22" Dell SP2009W 1680x1050 
PowerCase
CORSAIR HX 750W Cooler Master HAF 922 
CPUMotherboardGraphicsRAM
Core 2 Duo 2.4Ghz Penryn T8300 Some logical board GMA X3100 4GB (2x2GB) DDR2 667Mhz 
Hard DriveOptical DriveOSMonitor
Hitachi 160 GB 5400 RPM SATA II Combo drive OSX 10.6.4 (Snow leopard) 13.3" 1280x800 TFT 
PowerCase
Dying battery White macbook case 
  hide details  
Reply
post #6 of 8
Bash handles strings just like C. It automatically appends a null terminator to the end of a string. All your strings should already have null terminators.

As far as syntax goes:
\
is a linebreak
I'm pretty sure \\0 is a null terminator.
post #7 of 8
You have to put it in double quotes.

P.S. You might also want to fix your thread title.
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
post #8 of 8
Eh, the reason \
doesnt work is because thats not a 'null terminator' nor have I ever heard of a 'null terminator' in bash. When working with bash \
is a newline character. Here is an example run this..

echo "OCN"

then run

echo "OCN" | tr -d '\
'

The second echo runs "trim delete newline" and will take out the spacing.
Desktop
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9550 EVGA 780SLi EVGA GTX285SSC 4GB OCZ Reaper HPC Edition 
Hard DriveOptical DriveOSPower
150GB Velociraptor x2 - RAID0 2 - Samsung Write Master's Window 7 64-bit 750 Watt OCZ 60 AMPs on +12v 
CaseMouse
LIAN LI PC-V2110B Black Logitech G3 
  hide details  
Reply
Desktop
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9550 EVGA 780SLi EVGA GTX285SSC 4GB OCZ Reaper HPC Edition 
Hard DriveOptical DriveOSPower
150GB Velociraptor x2 - RAID0 2 - Samsung Write Master's Window 7 64-bit 750 Watt OCZ 60 AMPs on +12v 
CaseMouse
LIAN LI PC-V2110B Black Logitech G3 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix