reads only the first word from file

This commit is contained in:
Yamashita Yuu 2014-03-24 19:23:36 +09:00
parent ea9214bb2e
commit 34065dddbb
2 changed files with 5 additions and 7 deletions

View file

@ -9,14 +9,12 @@ if [ -e "$VERSION_FILE" ]; then
# Read the first non-whitespace word from the specified version file. # Read the first non-whitespace word from the specified version file.
# Be careful not to load it whole in case there's something crazy in it. # Be careful not to load it whole in case there's something crazy in it.
IFS="${IFS}"$'\r' IFS="${IFS}"$'\r'
words=( $(cut -b 1-1024 "$VERSION_FILE") ) words=( $(cut -b 1-1024 "$VERSION_FILE" | awk '{ print($1) }') )
versions=("${words[@]}") versions=("${words[@]}")
if [ -n "$versions" ]; then if [ -n "$versions" ]; then
OLDIFS="$IFS" IFS=":"
IFS=:
echo "${versions[*]}" echo "${versions[*]}"
IFS="$OLDIFS"
exit exit
fi fi
fi fi

View file

@ -38,16 +38,16 @@ setup() {
@test "reads only the first word from file" { @test "reads only the first word from file" {
cat > my-version <<<"3.3.5 2.7.6 hi" cat > my-version <<<"3.3.5 2.7.6 hi"
run pyenv-version-file-read my-version run pyenv-version-file-read my-version
assert_success "3.3.5:2.7.6:hi" assert_success "3.3.5"
} }
@test "loads only the first line in file" { @test "loads *not* only the first line in file" {
cat > my-version <<IN cat > my-version <<IN
2.7.6 one 2.7.6 one
3.3.5 two 3.3.5 two
IN IN
run pyenv-version-file-read my-version run pyenv-version-file-read my-version
assert_success "2.7.6:one:3.3.5:two" assert_success "2.7.6:3.3.5"
} }
@test "ignores leading blank lines" { @test "ignores leading blank lines" {