Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

Search:

CA216      CA249      CA318

CA400      CA651      CA668


What is wrong with these Shell scripts?


  1.  
     
    # list files given in the argument:
    
    ls$1 
     
    
  2. 
    # find processes and kill them:
    # how do I know this script has never been run?
    
    for i in 'ps -f | grep textedit' 
    do 
     kill $i 
    done 
    
    
  3. 
    # what caused this do you think?
      
    Echo "some text" 
     
    Ls -al 
     
    
  4.  
    cd /
    cd ..
    
    
  5. 
    # list all files on disk, collect results in some output file:
    
    cd /
    ls -alR > outputfile.log
    
    
  6. 
    # substitute new text for old text in a number of files:
    
    read OLDTEXT
    read NEWTEXT
    
    for i in $* 
    do 
     sed -e "s|$OLDTEXT|$NEWTEXT|g" $i > $i 
    done 
    
    
  7.  
    # how do I know this script has never been run?
    
    find .   -name $1    > /dev/null 2> /dev /null
    
    
  8. 
    # how do I know this script has never been run?
    
    echo "enter old text" 
    read OLDTEXT 
     
    echo "enter new text 
    read NEWTEXT 
     
    


Feeds      w2mind.org

On Internet since 1987.