Last active
October 7, 2018 10:56
-
-
Save photonxp/056d3526d46d850722842b3ec2cd0e85 to your computer and use it in GitHub Desktop.
touch sh bash files with additional operations such as give file names and chmod them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Once the global warmth reaches a tipping point, | |
# the chain-reaction could be irreversible, | |
# so are we ready for the ticking bomb? | |
# Usage: | |
# ./touchsh file_name | |
# No touch operation if file already existed. | |
n_touch(){ | |
fpath=$1 | |
printf "$fpath" | grep -Eq '\.bash$' | |
if [ 0 -eq $? ] | |
then | |
echo "NOTICE:: Found name suffix .(ba)sh in input" | |
fpath_new=$fpath | |
else | |
fpath_new=$fpath.bash | |
fi | |
if [ -e $fpath_new ] | |
then | |
echo "NOTICE:: $fpath_new" | |
echo "NOTICE:: File already existed. Exit with no operation." | |
return 1 | |
fi | |
touch $fpath_new | |
printf "#!/bin/bash\n\n" > $fpath_new | |
chmod u+x $fpath_new | |
echo $fpath_new | |
} | |
fpaths_str="$@" | |
for fpath in $fpaths_str | |
do | |
n_touch $fpath | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Usage: | |
# ./touchsh file_name | |
# No touch operation if file already existed. | |
n_touch(){ | |
fpath=$1 | |
printf "$fpath" | grep -Eq '\.sh$' | |
if [ 0 -eq $? ] | |
then | |
echo "NOTICE:: Found name suffix .(ba)sh in input" | |
fpath_new=$fpath | |
else | |
fpath_new=$fpath.sh | |
fi | |
if [ -e $fpath_new ] | |
then | |
echo "NOTICE:: $fpath_new" | |
echo "NOTICE:: File already existed. Exit with no operation." | |
return 1 | |
fi | |
touch $fpath_new | |
printf "#!/bin/sh\n\n" > $fpath_new | |
chmod u+x $fpath_new | |
echo $fpath_new | |
} | |
fpaths_str="$@" | |
for fpath in $fpaths_str | |
do | |
n_touch $fpath | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment