scripts interview questions

Top 15 scripts interview questions

8988 Jobs openings for scripts

How to execute a script just by double clicking like .EXE files in Windows?

How can I make a bash script executable by double clicking just like .exe files in Windows? I tried creating a launcher and assigning the script to it, but there are two consequences:

  1. the terminal twinkles, disappears, and nothing is done.
  2. you must specify to run in terminal in order to work.

I have a script that installs tomcat on an offline PC, including all dependencies of tomcat in the script. I need to make the script work on double clicking like windows since most who use the script will not be familiar with Ubuntu.

Forget the above explanation. I want to make a script that can be run by double-clicking on it, without using the terminal. Anybody knows how?

Source: (StackOverflow)

How can I determine whether a shellscript runs as root or not? [duplicate]

Possible Duplicate:
How can a script check if it’s being run as root?

This is something I've been curious about. I make a lot of small bash scripts (.sh files) to do tasks that I routinely do. Some of those tasks require everything to be ran as superuser. I've been curious: Is it possible to, within the BASH script prior to everything being run, check if the script is being run as superuser, and if not, print a message saying You must be superuser to use this script, then subsequently terminate the script itself. The other side of that is I'd like to have the script run when the user is superuser, and not generate the error.

Any ideas on coding (if statements, etc.) on how to execute the aforementioned?

Source: (StackOverflow)

How do I create a deb package for a single python script?

I have a single python script that I want to distribute as a deb package. It is a indicator which shows local date in Unity panel. I did follow create a .deb Package from scripts or binaries but I could not create a deb package because it fails.

Can someone give me a step-by-step instruction on what I should do? As far as I know this script depends on python-appindicator.

I do not want any links to Debian/Ubuntu packaging instructions. I have seen most of them. I don't find them beginner friendly.

Source: (StackOverflow)

How can I make a script that opens terminal windows and executes commands in them?

I have three scripts I need to run when I start up my Ubuntu machine, they start services I use in my development environment.

To do that, I manually open three terminals and type in the commands.

Is there any way to create a script that will open three terminals and execute one command in each of these? (Each command should be in a separate terminal window so I can see their output).

Source: (StackOverflow)

How can I create a select menu in a shell script?

I'm creating a simple bash script and I want to create a select menu in it, like this:


echo "Choose your option:"

1) Option 1  
2) Option 2  
3) Option 3  
4) Quit  

And according to user's choice, I want different actions to be executed. I'm a bash shell scripting noob, I've searched the web for some answers, but got nothing really concrete.

Source: (StackOverflow)

Can I make the webcam take a picture when an incorrect password is entered?

I am using a laptop . I was thinking to have a support in my Ubuntu machine. When an incorrect password is entered, a picture is taken later revealing who has been trying to gain access.

I have searched around and the only thing I have found is stuff to do this on Macs. Is It possible to write a script for Ubuntu to do same .

If possible then what is a script or Software to make this happen.

Source: (StackOverflow)

Command to append line to a text file without opening an editor

Assuming i have a line that i want to add to a file without opening an editor.

How could i append this line

alias list='ls -cl --group-directories-first'

to this file


Source: (StackOverflow)

How to add a shell script to launcher as shortcut [duplicate]

Possible Duplicate:
How can I edit/create new launcher items in Unity by hand?
How can I create launchers on my desktop?

I want to add some shell scripts in my launcher as shortcuts..

They are located deep inside and i have to navigate to it every time to execute them...

I tried this link where the 2nd answers seems to solvee it but as said in comments neither can i find any option to add a launcher..

I guess it existed in 11.04 with a "+" button on launcher but i use 12.04.

So how do i get this working?? And i need those commands everytime for sure..!

Source: (StackOverflow)

How to read complete line in 'for' loop with spaces

I am trying to run a for loop for file and I want to display whole line. But instead its displaying last word only. I want the complete line.

for j in `cat ./file_wget_med`

echo $j


result after run:


Here is my data:

$ cat file_wget_med
2013-09-11 14:27:03 ERROR 404: Not Found.

Source: (StackOverflow)

Bash remove first and last characters from a string

I have a string like that:


And i want to get a new string called in someway (like string2) with the original string without the two | at the start and at the end of it

so that i will have this


is that possible in bash?

Source: (StackOverflow)

How can I get a list of all repositories and PPAs from the command line into an install script?

I know how to list all packages installed on my system.

But how could I get a list of all repositories and PPA's?

I know I can look into /etc/apt/sources.list and /etc/apt/sources.list.d, but I'm looking for a way to generate a script that executes all apt-add-repository commands on a new system (that sorts out getting all keys).

Any ideas?

Source: (StackOverflow)

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

if I write,

echo "foo"


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)

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 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)

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)