I have only one condition to check. And i would like to use the if-else construct in shell script. How do i write it. Most of the docs show that the construct is doing multiple aspects thats why they use
if []; then
echo "do something"
elif
echo "somethingelse"
else
echo "something 2"
fi
But in my case i am writing my construct like the below. It gives syntax issues.
#!/bin/sh
hadoopFileList=`hadoop fs -ls /app/SmartAnalytics/Apps/service_request_transformed.db/sr_denorm_bug_details/ | sed '1d;s/ */ /g' | cut -d\ -f8`
destination="/apps/phodisvc/creandoStaging"
scpData()
{
for file in $hadoopFileList
do
echo $file
echo "copying file to the staging directory"
hadoop fs -copyToLocal $file $destination
sleep 2s
echo "deleting the file"
echo ${file##*/}
done
}
if [[ -d "$destination" ]]; then
#file exists copy data
scpData()
else
#else create directory and copy data
mkdir -p $destination
scpData()
fi
mkdir -palready does nothing (successfully) when the directory exists. Why do you have theifat all?()wrong:scpData()right:scpDataonly function definition needs()