Berkeley CSUA MOTD:Entry 19911
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/07/09 [General] UID:1000 Activity:popular
7/9     

2000/11/26-28 [Computer/SW/Unix, Computer/SW/Languages] UID:19911 Activity:moderate
11/25   #!/bin/sh
        : How do I make bourne shell subroutine modify a global variable?
        : Want to use VAR1 and VAR2 after the subroutine parses my_input_file
        foo() {
        while read VAR1 VAR2
        do
          echo "Reading $VAR1 and $VAR2"
          export VAR1 VAR2
        done < my_input_file
        export VAR1 VAR2
        }
        foo
        echo VARS = $VAR1 , $VAR2 # VAR1 & VAR2 are blank/empty-strings!
        \_ while loop is executed in a separate shell in bourne shell,
           thus its not possible.
           \_ wrong. but the order is backwards. Try this.
              #!/bin/sh
              export GLOBALVAR
              GLOBALVAR=1
              change(){
                GLOBALVAR=2
              }
              change
              echo $GLOBALVAR
                     \_ too complicted:
                           #!/bin/sh
                           change() {
                              GLOBAL=2;
                           }
                           GLOBAL=1;
                           echo GLOBAL is $GLOBAL
                           change
                           echo GLOBAL is $GLOBAL

                  \_ uh, no you are wrong. In *bourne* shell (virutally
                     unchanged since AT&T UNIX Version 7) while loops
                     are a separate process (I'm looking at the code
                     right now) when the input or output of the shell
                     is redirected. To avoid this you need to use exec
                     to save and restore STDIN. Try something like:
                     #!/bin/sh

                     myfunc () {
                       exec 5<&0 < "$1";
                       while read LINE ;
                       do
                          COUNT=`echo $COUNT + 1 | bc`
                       done
                       exec 0<&5 5<&-
                    }

                    COUNT=0
                    echo COUNT is $COUNT
                    myfunc /etc/passwd
                    echo COUNT is $COUNT
        \_ Get new shell.
           \_ Stick with Bourne shell as Steve and GOD intended.
ERROR, url_link recursive (eces.Colorado.EDU/secure/mindterm2) 2025/07/09 [General] UID:1000 Activity:popular
7/9     

You may also be interested in these entries...
2012/8/29-11/7 [Computer/SW/Security] UID:54467 Activity:nil
8/29    There was once a CSUA web page which runs an SSH client for logging
        on to soda.  Does that page still exist?  Can someone remind me of the
        URL please?  Thx.
        \_ what do you mean? instruction on how to ssh into soda?
           \_ No I think he means the ssh applet, which, iirc, was an applet
              that implemented an ssh v1 client.  I think this page went away
	...
2012/9/20-11/7 [Computer/SW/Unix, Finance/Investment] UID:54482 Activity:nil
9/20    How do I change my shell? chsh says "Cannot change ID to root."
        \_ /usr/bin/chsh does not have the SUID permission set. Without
           being set, it does not successfully change a user's shell.
           Typical newbie sys admin (on soda)
           \_ Actually, it does: -rwsr-xr-x 1 root root 37552 Feb 15  2011 /usr/bin/chsh
	...
2012/9/24-11/7 [Computer/SW/Languages, Computer/SW/Unix] UID:54484 Activity:nil
9/24    How come changing my shell using ldapmodify (chsh doesn't work) doesn't
        work either? ldapsearch and getent show the new shell but I still get
        the old shell on login.
        \_ Scratch that, it magically took my new shell now. WTF?
           \_ probably nscd(8)
	...
2012/3/29-6/4 [Computer/HW/Memory, Computer/HW/CPU, Computer/HW/Drives] UID:54351 Activity:nil
3/29    A friend wants a PC (no mac). She doesn't want Dell. Is there a
        good place that can custom build for you (SSD, large RAM, cheap video
        card--no game)?
        \_ As a side note: back in my Cal days more than two decades ago when
           having a 387SX made me the only person with floating-point hardware,
           most machines were custom built.
	...
2012/4/27-6/4 [Computer/SW/Languages/Misc, Computer/SW/Unix] UID:54372 Activity:nil
4/27    I wrote a little shell script to collect iostat data:
        #!/bin/bash
        DATE=`date +%m%d`
        DATADIR=/var/tmp/user
        OUTPUTFILE=$DATADIR/$DATE.out
        while true
	...
2012/1/27-3/26 [Computer/SW/Unix] UID:54299 Activity:nil
1/27    Interesting list of useful unix tools. Shout out to
        cowsay even!
        http://www.stumbleupon.com/su/3428AB/kkovacs.eu/cool-but-obscure-unix-tools
        \_ This is nice.  Thanks.
	...
2011/10/26-12/6 [Computer/SW/Unix] UID:54202 Activity:nil
10/24  What's an easy way to see if say column 3 of a file matches a list of
       expressions in a file? Basically I want to combine "grep -f <file>"
       to store the patterns and awk's $3 ~ /(AAA|BBB|CCC)/ ... I realize
       I can do this with "egrep -f " and use regexp instead of strings, but
       was wondering if there was some magic way to do this.
       \_ UNIX has no magic. Make a shell script to produce the ask or egrep
	...
2011/5/19-7/13 [Computer/SW/Languages/Misc] UID:54115 Activity:nil
5/19    If script A runs, and calls script B ..... is it possible for me to exit\
        script A based on results of script B and not continue?
        \_ assume any shell
        \_ Yes.
           \_ without passing the result to some stupid temp file?
              \_ It sounds like you want "scriptb || exit", which will run
	...
2010/3/8-30 [Computer/SW/Unix] UID:53745 Activity:nil
3/8     I have a mod_rewrite question that I think should be straight-
        forward but I think I'm not getting something.
        I have a virtual server with some root, say /home/user/public_html/
        and in there I have two subdirs, say /app1/ and /app2/
        and i want the following:
        http://mysite/app1   -->   /home/user/public_html/app1
	...
2009/8/19-9/1 [Computer/SW/Unix] UID:53285 Activity:nil
8/18    Hi again, new freebsd guy here again, in bash I was able to go
        LD_LIBRARY_PATH=/opt/foo/lib ./runmyapp
        I managed to do this in tcsh by using setenv in a shell script
        that setenv's the lib path and then executes $1, just wondering
        if there was a way to do it in 1 line from the cmd line as in bash?
        Thanks, btw %2c or %3c worked.  Freebsd, tcsh and vi forever!
	...