The sed command (above) suggests that a slash "/" is permitted or
expected as part of the input variable. The slash marks directories
and subdirectories. The 'touch' command is invoked on the unaltered
input. A good script checks to see if a directory exists before trying
to touch a file in that directory.
In the above, the sed script removes slashes from the output name,
with the result that when the 'mv' command executes, a file from a
subdirectory (if it exists) is moved to the current directory.
Since the filename is input manually, I don't think that the slash was
intended as an input character. Here is a version of the script that
should fit this request. It may not work correctly if you are using an
obsolete version of sed.
#!/bin/ksh
clear
echo -n "Enter file name: "
read file
file="${file}".c
touch "${file}"
echo "original filename:" ${file}
newfile=`echo "${file}" | sed -e '
s/ /_/g; # convert spaces to underscore
s/^\([0-9]\.\)/0\1/; # change ^2. to ^02., etc
:loop
s/\.\([0-9][._]\)/.0\1/; # chg .3. to .03., .4_ to .04_, etc
t loop
'`
echo " altered filename:" ${newfile}
[[ "${file}" != "${newfile}" ]] && mv "${file}" ${newfile}
echo vi ${newfile}
Hope this helps.