English (UK)
Français (France)
Brezhoneg (Breizh)

#!/bin/bash Bash line adder


	#!/bin/bash
	#Add the command to use bash at the beginning of a file
	if [ $# -eq 0 ]
	then
		echo $0 FILE [FILE...]
		exit 1
	fi

	for fileName in $*
	do
		if [ -f $fileName ]
		then
			if [ -r $fileName ]
			then
				if [ -w $fileName ]
				then
					if [ -z `grep -m 1 '#!/bin/bash' $fileName` ]
					then
						echo -e "#!/bin/bash\n"`cat $fileName` > $fileName
						chmod u+x $fileName
						echo $fileName is now executable
					else
						echo $fileName already contains the string '#!/bin/bash'
						chmod u+x $fileName
					fi
				else
						echo You are not allowed to modify $fileName
						exit 10
				fi
			else
				echo $fileName is unreadable
				exit 20
			fi
		else
			echo $fileName is not a file
			exit 30
		fi
	done 

Add #!/bin/bash to all the files of a directory. This is an example of how to automatize a task and could be used to add other headers (php, copyrights, creation date...) or footers

Back to the projects page