debuti
November 26th, 2008, 05:50 PM
Hello everyone
I mean, i use to code bash scripts all the time to automate tasks, but has reached a moment where it is likely that people that i know needs them, and the problem is that they do not use linux (or bash).
Well, my idea is to keep writing these scripts in a more portable scripting language, such as perl or python, but I do not like to lose usual bash/unix commands/utilities as find, grep, sort, awk, diff, du, date, etc. and if its posibble id like to be able to use some common apis like gdata or flickr's.
What scripting language do you recommend me for this?
Should I stay in coding bash?
With what language could you achieve faster developing and more portability?
Thanks for the reading :)
P.D.
Example useful script that i coded
#!/bin/bash
################################################## ##############################
# Author: Borja Garcia <debuti@gmail.com>
# Program: getFullPath.sh
# Descrip: Returns the full path of the given file (standalone function to
# include in your own scripts)
# Version: 0.0.0
# Date: 2008-11-14:18:47:00
# License: This script doesn't require any license since it's not intended to be
# redistributed.
# In such case, unless stated otherwise, the purpose of the author is
# to follow GPLv3.
# Version: 0.0.0 (2008-11-14:18:47:00)
# - Initial release
################################################## ##############################
# Usage function
function usage() {
# Tell the user how to use me
echo "usage: $0 <valid file to get the full path>"
}
# Input validation function (getopts)
function checkInput() {
if [ $# -ne 1 ]; then
usage $0
exit -1
fi
}
# Helper functions
function getFullPath() {
file=""
actual=`pwd`
output=""
temp=""
if [ -e "$1" ]; then
file="$1"
else
return -1
fi
if [ `echo $file | cut -c1,1` = "/" ]; then
output=$file
else
output="$actual"/"$file"
output=`echo $output | sed -e "s/\/\.\//\//g"` #Ignore /./
while [ `echo $output | grep "/../"` ]; do
output=`echo $output | sed -e "s/\/[^\/^(\.\.)]*\/\.\.\//\//g"` #Delete /somewhere/../
output=`echo $output | sed -e "s/^\/\.\.\//\//g"`
done
output=`echo $output | sed -e "s/\/\//\//g"` #Ignore //
fi
if [ -e "$output" ]; then
echo "$output"
else
echo "Can't do it :S $output" 1>&2
return -2
fi
}
# Main function
function main() {
getFullPath "$1"
}
# Entry point
checkInput $@
main $@
I mean, i use to code bash scripts all the time to automate tasks, but has reached a moment where it is likely that people that i know needs them, and the problem is that they do not use linux (or bash).
Well, my idea is to keep writing these scripts in a more portable scripting language, such as perl or python, but I do not like to lose usual bash/unix commands/utilities as find, grep, sort, awk, diff, du, date, etc. and if its posibble id like to be able to use some common apis like gdata or flickr's.
What scripting language do you recommend me for this?
Should I stay in coding bash?
With what language could you achieve faster developing and more portability?
Thanks for the reading :)
P.D.
Example useful script that i coded
#!/bin/bash
################################################## ##############################
# Author: Borja Garcia <debuti@gmail.com>
# Program: getFullPath.sh
# Descrip: Returns the full path of the given file (standalone function to
# include in your own scripts)
# Version: 0.0.0
# Date: 2008-11-14:18:47:00
# License: This script doesn't require any license since it's not intended to be
# redistributed.
# In such case, unless stated otherwise, the purpose of the author is
# to follow GPLv3.
# Version: 0.0.0 (2008-11-14:18:47:00)
# - Initial release
################################################## ##############################
# Usage function
function usage() {
# Tell the user how to use me
echo "usage: $0 <valid file to get the full path>"
}
# Input validation function (getopts)
function checkInput() {
if [ $# -ne 1 ]; then
usage $0
exit -1
fi
}
# Helper functions
function getFullPath() {
file=""
actual=`pwd`
output=""
temp=""
if [ -e "$1" ]; then
file="$1"
else
return -1
fi
if [ `echo $file | cut -c1,1` = "/" ]; then
output=$file
else
output="$actual"/"$file"
output=`echo $output | sed -e "s/\/\.\//\//g"` #Ignore /./
while [ `echo $output | grep "/../"` ]; do
output=`echo $output | sed -e "s/\/[^\/^(\.\.)]*\/\.\.\//\//g"` #Delete /somewhere/../
output=`echo $output | sed -e "s/^\/\.\.\//\//g"`
done
output=`echo $output | sed -e "s/\/\//\//g"` #Ignore //
fi
if [ -e "$output" ]; then
echo "$output"
else
echo "Can't do it :S $output" 1>&2
return -2
fi
}
# Main function
function main() {
getFullPath "$1"
}
# Entry point
checkInput $@
main $@