Sunday, January 6, 2013

Is it morally or ethically wrong to modify a windows computer to accept linux terminal commands in CMD?

Q. For example,
Run>Terminal>ifconfig /all

A. Nope, although Cygwin is probably a more practical alternative. It's still Windows, after all.

What is the command to display the results of adding to numbers in Linux/Ubuntu terminal?
Q. On older versions of Ubuntu, you used to be able to do the following:

sum='expr 4 + 5'
echo $sum


and this would display 9



But this doesn't work of the newer version.



How do I perform that same task on the new version of Ubuntu?

A. !/bin/sh
pushd . > /dev/null
cd /home/profiles
echo "Counting Spam..."
for i in `ls * -d`; do
MESSAGES=`find $i/Maildir/.Spam | grep anubis`
if [ -z "$MESSAGES" ]
then
continue
fi
COUNT=`echo $MESSAGES | wc -w`
echo $COUNT Spam messages for $i trapped;
for i in $MESSAGES; do
grep -h "Content analysis details" $i | cut -d : -f 2 | cut -d , -f 1 | cut -d \( -f 2;
done
done
popd > /dev/null

What is the command to display the results of adding to numbers in Linux/Ubuntu terminal?
Q. On older versions of Ubuntu, you used to be able to do the following:

sum='expr 4 + 5'
echo $sum


and this would display 9



But this doesn't work of the newer version.



How do I perform that same task on the new version of Ubuntu?

A. This kind of operation most definitely still does work. It looks like you're using the wrong sort of quotes, though. Unix/Linux shells differentiate between double quotes ("), single quotes (') and backtick quotes (`). You need to use backticks for command evaluation.

  sum=`expr 4 + 5`
  echo $sum

However, the newer approach is to use bracketed expressions, like this -

  sum=$((4+5)) # Do the maths directly in the shell
  sum=$(expr 4 + 5) # Use expr to calculate the result

  id=$(id -u) # the output of the id -u command

the $((...)) expression can also handle variable names, like this -

  a=5
  sum=$((a+4))




Powered by Yahoo! Answers

No comments:

Post a Comment