Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › How to pull Variables from a file?
New Posts  All Forums:Forum Nav:

How to pull Variables from a file?

post #1 of 2
Thread Starter 
Hey guys and girls. I'm trying to write a bash script, and I'm trying to pull 2 variables from a file. The menu I'm currently working on is
Code:
echo
echo "============================================================"
  echo " Build Menu. Please proceed in order. If you have completed"
  echo " a step previously (IE prepare system or downloaded the source"
  echo " for the same version you are rebuilding, you may skip. Just"
  echo " select update, then build."
  echo "============================================================"
  echo
echo " Device Selection"
  echo 
  echo "> Build Menu"
  echo 
  echo
  echo " 1) - Prepare your Environment" 
  echo " 2) - Prepare ADB"
  echo " 3) - Download the Source"
  echo " 4) - Prepare source for your $device and $version "
  echo " 5) - Compile the source."
  echo " 6) - Build a Custom kernel (If Available)"
  echo " U) - Check for source updates"
  echo " B) - Go Back"
  echo " X) - Quit"
  echo 
..

(this is nowhere near the full set of code in the file. just fyi)

I'm trying to make the script pull from variables.txt that is created and populated earlier.

I tried
Code:
while read varibles.txt
do
start.sh $version $device ;;
but it just hangs


Any help? thanks peeps!
RedMyst
(18 items)
 
   
CPUMotherboardGraphicsGraphics
Intel Core i3/i5/i7 TZ77B NVIDIA GeForce GTX 560 Ti  Powercolor HD 7770 
RAMHard DriveHard DriveOptical Drive
G. Skill Sniper Mushkin Chronos SSD Western Digital 640gb SATA Sony Optiarc AD-7280S-0B 
CoolingOSMonitorMonitor
Coolermaster Hyper 212+ Windows 8 Professional HANNspree 21.5" LED LCD Dell E228WFP 
KeyboardPowerCaseMouse
Microsoft Desktop 400 OCD ModXStream 700 Watt  Coolermaster HAF 912 CM Storm Inferno 
AudioAudio
Creative Labs WoW Soundblaster. Logitech X-140 
  hide details  
Reply
RedMyst
(18 items)
 
   
CPUMotherboardGraphicsGraphics
Intel Core i3/i5/i7 TZ77B NVIDIA GeForce GTX 560 Ti  Powercolor HD 7770 
RAMHard DriveHard DriveOptical Drive
G. Skill Sniper Mushkin Chronos SSD Western Digital 640gb SATA Sony Optiarc AD-7280S-0B 
CoolingOSMonitorMonitor
Coolermaster Hyper 212+ Windows 8 Professional HANNspree 21.5" LED LCD Dell E228WFP 
KeyboardPowerCaseMouse
Microsoft Desktop 400 OCD ModXStream 700 Watt  Coolermaster HAF 912 CM Storm Inferno 
AudioAudio
Creative Labs WoW Soundblaster. Logitech X-140 
  hide details  
Reply
post #2 of 2
have your variables in another shell script then import them with the dot space filename method; ". filename"
Code:
# variables.txt
var1=foo
var2=bar

then in your main shell script import the variables like so:
Code:
#!/bin/sh

# import vars
. variables.txt

# print the imported vars to screen
# (not needed - just here to prove this works)
set | grep var[12]

echo "do stuff"

Personally I wouldn't name your variables as .txt. Use either .conf or no extension at all.

Also if these are variables for a daemon then it's best to keep the conf in /etc/conf.d with the other daemon configs (though systemd probably does away with that now).
Edited by Plan9 - 11/12/12 at 12:20am
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › How to pull Variables from a file?