Skip to content

Posts tagged ‘shell script’

23
nov

Using conditional expressions to improve your shell scripts

You can use these very simple shell script conditional expressions to improve your home-made scripts, making them more efficient and easy to mantain.

To check if a file exists and it’s executable, use:

#!/bin/bash
FILE=/usr/bin/passwd

if [ -x $FILE ];
then
 echo "File $FILE exists and it is executable"
else
 echo "File $FILE does not exists or it isnt executable"
fi

There are several other options. Here’s the full available conditional expressions:

-e: Returns true value if file exists
-f
: Return true value if file exists and regular file
-r: Return true value if file exists and is readable
-w: Return true value if file exists and is writable
-x: Return true value if file exists and is executable
-d: Return true value if exists and is a directory

Have fun improving your scripts !

23
set

Teste: Mod Syntax Highlighting

Encontrei este mod e passarei a usá-lo de agora em diante.
Quem quiser ter um igual é só instalar este mod aqui.

1
2
3
4
5
public class Hello {
  public static void main(String[] args) {
    System.out.println("Olá mundo!");
  }
}
1
2
3
4
#!/bin/bash
FILE=/etc/file
echo $FILE
echo "string"
<?php
  function foo() {
    echo "Olá mundo!\\n";
  }
?>
?View Code DELPHI
begin
   function teste
   showmessage('Testandoo');
end;
Twitter RSS Feed Email Subscription Facebook Technorati FriendFeed