EzDevInfo.com

scripts interview questions

Top scripts frequently asked interview questions

Why does Python in Linux require the line #!/usr/bin/python?

Pretty simple question: In Linux, why does Python require the line

#!/usr/bin/python

at the start of a python file, since Windows doesn't?

What does it do? 'cause the description "Links to Python" is a bit vague...


Source: (StackOverflow)

How to make Skype use notify-osd?

How do I make Skype use the default Ubuntu notify-osd to display notifications (incoming messages, users connecting, etc.) instead of the Skype's own "ugly" message box?


Source: (StackOverflow)

Advertisements

What is the difference between "source" and "." in bash?

As the question says, what is the difference between executing a script with source command and with . , i.e.:

source /some/script

and

. /some/script

Source: (StackOverflow)

Beep in shell script not working?

I'd like to use a beep sound in a shell script. Unfortunately none of the methods I found via Google work for me.

I tried

echo -e '\a'

echo -ne '\007'

and the command beep after I installed it via apt.

What could be the reason?


Source: (StackOverflow)

Repeat a command every x interval of time in terminal?

How can I repeat a command every interval of time , so that it will allow me to run commands for checking or monitoring directories ?

There is no need for a script, i need just a simple command to be executed in terminal.


Source: (StackOverflow)

Should I save my scripts with the .sh extension?

I have some functional scripts and I want to copy to /usr/bin I want to use them as normal terminal commands. Is it a good practice to use them with the .sh extension or can I save them without extension?


Source: (StackOverflow)

I've downloaded a .sh file - how do I install this?

I'm new to Ubuntu and know installing programs only from window. It is very easy there: Just double-click the setup.exe and the things start.

But how do I install a program on Ubuntu?

I want to install something which I couldn't find in the Ubuntu Software Center. I downloaded a .sh file and now I don't know what to do with it.


Source: (StackOverflow)

'chmod u+x' versus 'chmod +x'

What is the difference between chmod u+x and just chmod +x? I have seen a ton of tutorials that say to use u+x to make scripts executable. However, the u is not mentioned in the chmod help or manual. Omitting the u doesn't seem to have any effect either. Is it just a deprecated argument? Thanks.


Source: (StackOverflow)

bashrc or bash_profile?

I know the difference between the two bash login scripts:

.bashrc is run only by "non-login" shells.

.bash_profile (or .bash_login or .profile) is executed by "login" shells.

Does anyone have some good examples of what things that are a better fit for login-only execution, such that I'd only put them in .bash_profile, but they wouldn't really make sense in .bashrc?

(I know most of us source .bashrc out of .bash_profile, so there doesn't seem to be much point in the opposite question...)


Source: (StackOverflow)

ssh: automatically accept keys

I've written this small utility script:

for h in $SERVER_LIST; do ssh $h "uptime"; done

When a new server is added to $SERVER_LIST, the script is stopped with:

The authenticity of host 'blah.blah.blah (10.10.10.10)' can't be established.
RSA key fingerprint is a4:d9:a4:d9:a4:d9a4:d9:a4:d9a4:d9a4:d9a4:d9a4:d9a4:d9.
Are you sure you want to continue connecting (yes/no)?

I've tried yes:

for h in $SERVER_LIST; do yes | ssh $h "uptime"; done

with no luck.

Is there a way to parametrize ssh to automatically accept any new key?


Source: (StackOverflow)

Is #!/bin/sh read by the interpreter?

In bash or sh, I guess anything which starts with # is a comment.

But in bash scripts we write:

#!/bin/bash

And in Python scripts, there is:

#!/bin/python

Does this mean that # by itself is a comment whereas #! is not?


Source: (StackOverflow)

When to use () vs. {} in bash?

I'm studying shell scripting with bash and I need to know the difference between (...) and {...}. How does one select between the two when writing a script?


Source: (StackOverflow)

What is the difference between ./ and sh to run a script?

I have written a simple script. When I runsh <myscriptname.sh>, i got the correct output, but when I run ./<myscriptname.sh>, I got an error.

What is difference between when I do sh and ./?


Source: (StackOverflow)

Differences between /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin [duplicate]

This question already has an answer here:

I'm running an Ubuntu Server 13.04, but I see the same on a 12.04: I have six directories with command files. These are:

  • /bin
  • /sbin
  • /usr/bin
  • /usr/sbin
  • /usr/local/bin
  • /usr/local/sbin

What are the differences between these?
For example: if I'm writing my own scripts, where should I add these?


Source: (StackOverflow)

What is difference between #!/bin/sh and #!/bin/bash?

if I write,

#!/bin/bash
echo "foo"

or

#!/bin/sh
echo "foo"

both yields same. I have seen some scripts starting with #!/bin/sh or #!/bin/bash. Is there any difference between them?


Source: (StackOverflow)