ubuntu 12.04 - execute bash commands with options from a file -


i having hard time executing bash commands (with options) read text file. in script there's loop reads commands file errors out:

cat com.txt apt-get update 

my script:

for in `cat com.txt` ; sudo bash -c $i ; done; 

the error msg displayed is:

apt 1.0.1ubuntu2 amd64 compiled on oct 28 2014 20:55:14 usage: apt-get [options] command        apt-get [options] install|remove pkg1 [pkg2 ...]        apt-get [options] source pkg1 [pkg2 ...]  apt-get simple command line interface downloading , installing packages. used commands update , install.  commands:    update - retrieve new lists of packages    upgrade - perform upgrade    install - install new packages (pkg libc6 not libc6.deb)    remove - remove packages    autoremove - remove automatically unused packages    purge - remove packages , config files    source - download source archives    build-dep - configure build-dependencies source packages    dist-upgrade - distribution upgrade, see apt-get(8)    dselect-upgrade - follow dselect selections    clean - erase downloaded archive files    autoclean - erase old downloaded archive files    check - verify there no broken dependencies    changelog - download , display changelog given package    download - download binary package current directory  options:   -h  text.   -q  loggable output - no progress indicator   -qq no output except errors   -d  download - not install or unpack archives   -s  no-act. perform ordering simulation   -y  assume yes queries , not prompt   -f  attempt correct system broken dependencies in place   -m  attempt continue if archives unlocatable   -u  show list of upgraded packages   -b  build source package after fetching   -v  show verbose version numbers   -c=? read configuration file   -o=? set arbitrary configuration option, eg -o dir::cache=/tmp see apt-get(8), sources.list(5) , apt.conf(5) manual pages more information , options.                        apt has super cow powers. bash: update: command not found 

in example, you're not executing whole line. execute apt-get (which expects argument) , update (which not command).

just use source of execute command inside file bash (execution bit not needed):

source com.txt 

Comments