Schreibe ein Shellskript, das 10 Dateien mit eindeutigem Namen erzeugt

Solution
  • #!/bin/bash
    
    dirname=files
    filename=file_0
    counter=0
    
    while [ -d "$dirname" ]
    do
        dirname="${dirname%_*}"_$counter
        (( counter++ ))
    done
    
    mkdir "$dirname"
    cd "$dirname"
    counter=0
    
    for a in {0..9}
    do
        while [ -e "$filename" ]
        do
            filename="${filename%_*}"_$counter
            (( counter++ ))
        done
    
        touch "$filename"
    done
    
  • URL:
  • Language:
  • Subjects: programming
  • Type: Name
  • Duration: 40min
  • Credits: 3
  • Difficulty: 0.5
  • Tags: hpi shell bash
  • Note:
    HPI, Programmiertechnik 1
  • Created By: adius
  • Created At:
    2013-04-12 16:49:14 UTC
  • Last Modified:
    2014-07-21 11:56:51 UTC