Dr. Mark Humphrys

School of Computing. Dublin City University.

Online coding site: Ancient Brain

coders   JavaScript worlds

Search:

Free AI exercises


What is wrong with these Shell scripts?


  1.  
     
    # list files given in the argument:
    
    ls$1 
     
    
  2. 
    # what caused this do you think?
      
    Echo "some text" 
     
    Ls -al 
     
    
  3. 
    # list all files on disk, collect results in some output file:
    
    cd /
    ls -alR > outputfile.log
    
    
  4. 
    # 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 
    
    
  5.  
    # how do I know this script has never been run?
    
    find .   -name $1    > /dev/null 2> /dev /null
    
    
  6. 
    # how do I know this script has never been run?
    
    echo "enter old text" 
    read OLDTEXT 
     
    echo "enter new text 
    read NEWTEXT 
     
    


ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.      New 250 G VPS server.

Note: Links on this site to user-generated content like Wikipedia are highlighted in red as possibly unreliable. My view is that such links are highly useful but flawed.