I want to process a group of files.
pi@raspberrypi:~/A6.1 $ ls -1 0bd57df4.code 0bd57df4.enc 3189204c.code 3189204c.enc 39f831fb.code 39f831fb.enc 68ff6d19.code 68ff6d19.enc find.sh test.sh I run a script (find.sh) that searches for files by the mask, and runs another script (test.sh) and passes the name of the found file to the parameter.
In test mode, I want to display the full file name and the shortened name without an extension.
The contents of the file find.sh:
#!/bin/bash find -name '*.enc' -printf "%f\0" | xargs -0 -n 1 ./test.sh The contents of the file test.sh:
# !/bin/bash NAMEFILE=$1 FULLNAME=$NAMEFILE CUTNAME=`echo ${NAMEFILE:0:6}` echo "FULLNAME - "$FULLNAME echo "FILENAME - $CUTNAME" The full name is displayed, there is no shortened name. Gives an error message. How do I process a variable?
pi@raspberrypi:~/A6.1 $ ./find.sh ./test.sh: 1: ./test.sh: Bad substitution FULLNAME - 68ff6d19.enc FILENAME - ./test.sh: 1: ./test.sh: Bad substitution FULLNAME - 3189204c.enc FILENAME - ./test.sh: 1: ./test.sh: Bad substitution FULLNAME - 39f831fb.enc FILENAME - ./test.sh: 1: ./test.sh: Bad substitution FULLNAME - 0bd57df4.enc FILENAME - When I run the test.sh file, it works.
pi@raspberrypi:~/A6.1 $ ./test.sh 68ff6d19.code FULLNAME - 68ff6d19.code CUTNAME - 68ff6d19
# !/bin/bashshould be#!/bin/bashor#! /bin/bash) so the./test.shscript is being executed byxargsdefault shell, which is likelysh#!. See unix.stackexchange.com/questions/276751/… But not between the#and the!.#!/bin/bashor#! /bin/bash" - the OP has a# !(hash-space-bang)