Bash: Create a file using some input

January 21, 2014 at 14:16:42
Specs: Macintosh , 2GB
I'm trying to create lnk files for idesk in Debian using bash. I've got some of it working but I can't figure out how to get the rest working. Here's the code:

#/bin/sh
if [ $# -eq 0 ]
then
echo "Usage mklink [name]"
fi

echo Caption:
read CAPTION

echo Command:
read APP

ICON=`locate .png | grep $APP | grep 32x32`
if [ $ICON -eq 0 ]
then
ICON=/usr/share/icons/nuoveXT2/32x32/mimetypes/unknown.png
fi

APP=`locate $APP | grep bin`

echo table Icon >> /root/.idesktop/$1.lnk
echo Caption: $CAPTION >> /root/.idesktop/$1.lnk
echo Command: $APP >> /root/.idesktop/$1.lnk
echo Icon: $ICON >> /root/.idesktop/$1.lnk
echo Width: 32 >> /root/.idesktop/$1.lnk
echo Height: 32 >> /root/.idesktop/$1.lnk
echo X: 24 >> /root/.idesktop/$1.lnk
echo Y: 32 >> /root/.idesktop/$1.lnk
echo end >> /root/.idesktop/$1.lnk


See More: Bash: Create a file using some input

Report •

#1
January 21, 2014 at 14:45:18
First, I have a question about your use of the locate command; I don't think you want to capture whatever the locate command returns:


ICON=`locate .png | grep $APP | grep 32x32`
if [ $ICON -eq 0 ]
then ....

Don't you want to check if a match is found with the locate command? In that case, it would be check the status sampling the exit code $?


ICON=`locate .png | grep $APP | grep 32x32`
if [ $? -eq 0 ]
then....

Next, I am assuming that root will execute this script since only root has permissions to create files in /root.



Report •

#2
January 21, 2014 at 14:57:10
What I'm trying to do is find the path of the executable and then find the icon for it and pipe it to the lnk in the root folder. Yes it's running as root for now. Gonna reconfigure things later.

Report •

#3
January 21, 2014 at 15:31:07
And my point is, that I doubt the contents of this command:

locate $APP | grep bin

will ever equal 0.


Report •
Related Solutions


Ask Question