aboutsummaryrefslogtreecommitdiff
path: root/bin/sqs
blob: 4da572ac63ded6373a9c8bcfff6f297ae02d8edc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
# Chop a trailing query string off filenames

# Check args
if [ "$#" -eq 0 ] ; then
    printf >&2 'Need a filename\n'
    exit 2
fi

# Iterate through the given files
for sn ; do

    # Strip trailing slash if any and then query string
    dn=${sn%/}
    dn=${dn%%\?*}
    
    # Ignore this file if its name wouldn't change
    [ "$sn" != "$dn" ] || continue

    # Attempt a rename, flag an error if there was one
    mv -- "$sn" "$dn" || ex=1
done

# Exit with 1 if there was any failed mv(1) run
exit "${ex:-0}"