The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …).

learn more… | top users | synonyms (1)

0
votes
2answers
43 views

Why can't I kill the shell using the PID obtained from the $$ special variable? [duplicate]

After I have learned that the $$ special variable holds the process number of the shell, I tried too kill the shell by simply: kill , however this did not work, I also tried some variations, but them ...
0
votes
2answers
43 views

What is the meaning of the number displayed by echo $$ ?

By accident I typed "echo $$" into the command line, but instead of an error message I got a 5 digit number. I repeated "echo $$" on different terminals and each time I got a 5 digit number. What is ...
0
votes
1answer
23 views

Historical bandwidth data in a console? (save/load statistics)

So, I found that nload and iftop displays the amount of data that passed and how fast. Now, is there anything like those that can save/load statistics? I want to measure the amount of data I download ...
0
votes
1answer
19 views

Calling of scripts between init.d and home directory of server

I have a script (server_up.sh)that automatically makes server up whenever server gets rebooted and is placed on linux server in home directory. I have made another script "up_server.sh" in init.d that ...
3
votes
1answer
147 views

eval limitation with piped commands

We have a shell script that builds a long piped command chain in a variable and executes it with eval (the following code is simplified to the essential): cmd="cat /some/files | grep -v \"this\" | ...
1
vote
2answers
70 views

linux/bash equivalent of mv -t

ls -al | grep -v '^d' | xargs mv -t mysubdir I use the above command extensively on Red Hat systems. It moves all files in the current directory to mysubdir $ mv --version Usage: mv [-f] [-i] [-e ...
0
votes
1answer
47 views

pass quoted string argument in sh script

I simply don't understand command-line (works): $ someprog -flag 'key1=val 1,key2=val 2,key3=val 3' sh direct (works): #!/bin/sh someprog -flag 'key1=val 1,key2=val 2,key3=val 3' sh variable ...
1
vote
1answer
49 views

Using the test command to create a directory if it doesn't exist

I was just wondering whether or not this script code would properly test for the existence of a dir2, and if it doesn't exist, then to create it. Dir1 already exists. [ ! -d /dir1/dir2 ] && ...
2
votes
3answers
87 views

What is a best practice to represent a boolean value in a shell script?

I know, that there are boolean values in bash, but I don't ever see them used anywhere. I want to write a wrapper for some often looked up information on my machine, for example, is this particular ...
14
votes
4answers
624 views

What is the difference between '$ . foo' and '$ ./foo'? [duplicate]

t is a simple script What is different between two case below : $ . t and $ ./t
1
vote
1answer
33 views

Redirection not overwriting file but just producing a blank one [duplicate]

I have a command that strives to just read a file and then comment out every single line in it indiscriminately, then overwrite the existing file. cat file | sed 's/^/#/g' > file But to my ...
0
votes
1answer
56 views

Run a Vim command from a bash script

This is related to a question I asked earlier but I would like to keep it separate in case anyone else can find use in it. I have a command that I am running on a file called dummy.out from the ...
2
votes
2answers
58 views

Bash command: is it possible to pass an argument before a custom command (function) or it must be only after:

I am wondering if it is possible to pass an argument to a custom command before the command? Let say I have custom command ping and I would like to pass the IP address before command: instead ping ...
0
votes
1answer
43 views

Two errors when running ssh in a bash script [duplicate]

I try to run this script against a remote machine, to carry out login check, but have some problems executing it with no errors. I have the following error when I run the script: The Error: bash: -c: ...
3
votes
2answers
94 views

Select added lines from file

I have two versions of a file where the newer one has some lines added. The files are sorted (think of wordlists) and I want to print out the newly added lines (given file1 and file2). I know how to ...
-1
votes
1answer
41 views

Shell script to get all the directory starting with a certain letters

I need to write some shell script to get all the directory that start with certain letters and save the result list in a txt file eg. -all uppercase directory -all directory that starts with "Ab" ...
0
votes
0answers
23 views

printf>stdin unusable with read [duplicate]

With read, sending "a" to stdin is not equivalent to pressing "a" (or use your favorite letter/key). Tested this: ~$ read -n1 & fg [1] 11620 read Then "typed" "a" into the read process stdin ...
0
votes
1answer
40 views

unexpected end of file [closed]

Have written a small script for our Windows machine but getting the below mentioned error. syntax error: unexpected end of file.Can you please help me to resolve it. I have attached only part of my ...
0
votes
3answers
57 views

Running sh file only works if cd'd to scripts directory

I'm trying to run a .sh file, through the ./file.sh syntax. I, wrongly, thought it'd be possible to run: ./usr/bin/foo/bar.sh which just yields "No such file or directory". However, if I run: cd ...
2
votes
3answers
119 views

Processing input line by line (with empty lines) from shell

In a shell script, I need to parse the output of a command line-by-line. The output may include empty lines, and these are relevant. I am using ash, not bash, so cannot resort to process substitution. ...
-1
votes
1answer
37 views

killall fails some time

Hi below is the script which is intended to kill all instances of the process "processName" but sometimes it is not able to kill the process and we see double instance of the same process how can I ...
0
votes
1answer
47 views

Make does not work when invoked from a bash script

So i just asked a question : for loop over a list This works perfectly now and outputs what i need. Now i want to link this to a makefile which should be called per variable in my list like this: ...
0
votes
2answers
67 views

Use a script for a telnet session

I have a problem with my script. It seems my password is wrong. #!/usr/bin/expect set ip [lindex $argv 0] spawn telnet $ip set timeout 10 expect "Login:" send "administrator\r" expect "Password:" ...
4
votes
3answers
239 views

Unpack file compressed in .txz and .tar with one command

I have a file compressed in *.txz. After unpacking it I received a *.tar file. Is there any way to unpack it twice with one command? I mean unpack file (*.tar).txz with one command? For know I'm do ...
1
vote
3answers
417 views

Read longest line in file using while read loop?

I've been googling but I can't find any scripts that uses the while loop to read the lines. I'm stuck and I'm not sure on where to start Heres the question: Write a bash script longestline.sh that ...
3
votes
1answer
56 views

How do you get the first file in each subdirectory matching a list of file extensions?

How do you get the first file in each subdirectory matching a list of file extensions? My goal is to run a program on just any one of the files in a series of subdirectories. For example, below ...
2
votes
1answer
91 views

How to print last login time?

I'd like to know how to set in .bashrc file to print the last login time of users when logging into another user in terminal. I do know that with who or last, but I'd like something a little more ...
7
votes
2answers
484 views

Bash - how to run a command after the previous finished? [duplicate]

Currently I have a script.sh file with the following content: #!/bin/bash wget -q http://exemple.com/page1.php; wget -q http://exemple.com/page2.php; wget -q http://exemple.com/page3.php; I want to ...
0
votes
0answers
34 views

checkbox to automated sql scripts run

I want to provide a menu in a shell script that offers a check list of SQL scripts to run. I actually need to execute the selected SQL scripts but it's about 20 of them and that make it hard to cover ...
1
vote
1answer
21 views

Comparing variables in arithmetic

Was wondering if someone can take the time to explain the following: I have a directory of files (PDF), which I place into an array. shopt -s nullglob # Set array ...
0
votes
2answers
33 views

is the shell a frontend to the terminal? [duplicate]

Is the shell only an addon to the terminal, so that a terminal daemon has to work in order to to start a shell as its frontend. What controll does the terminal exherts upon the shell?
0
votes
1answer
41 views

what is the difference betwwen starting a command with nohup and &? [duplicate]

nohub and & seem to have a similar effect on the surface, they both start processes without occupying the shell from which they have been started, how do they differ on a deeper level?
1
vote
0answers
34 views

A way to distinguish between interleaved output from two background processes

If I have two backgrounded processes that produce input to STDOUT or STDERR (e.g., two installation scripts), is there an easy way to make these two output streams distinguishable? I guess I can pipe ...
4
votes
2answers
54 views

How can I catch a command exit code for later, in a Makefile?

I have a makefile, with a test suite target, like so: rcheck: foo This shows the output from the foo command on stdout, and returns an exit code from foo which is handled by make as normal. ...
2
votes
1answer
55 views

Supply the same filename as argument to two commands [duplicate]

On a git conflict, I can currently do: git diff path/to/some/file.txt ... after reviewing the diff, usually I want to do: git checkout --theirs path/to/some/file.txt && git add ...
6
votes
2answers
209 views

Issue in Standard Output and Error [duplicate]

If I type cat > file.txt 2>&1 then file.txt is created with the content of cat's standard input.  But if I do cat > file.txt 1>&2 then file.txt is created, but the file is ...
3
votes
2answers
138 views

On Ctrl+C, kill the current command but continue executing the script

I have a bash script, wherein I execute a line, sleep for sometime and then tail -f my log file to verify a certain pattern is seen, I press ctrl +c to get out of tail -f and then move to the next ...
2
votes
1answer
81 views

Debian Linux: Start/run application/process in another virtual terminal

You'll have to bare with my my Linux terminology is pretty bad. When I say virtual terminal I'm talking about when you press ctrl+alt+ a function key (F1-F12). I think they are called virtual ...
0
votes
2answers
10 views

Manually executing a CRON - Confused about params

I have this code snippet: $CUSER=tim $APPDIR=/var/www/testing $APPVENV=/var/www/testing/ven cat > $APPDIR/cronfile << EOF PWD=$APPDIR/$CUSER PATH=$APPVENV/bin:\$PATH 0 2 * * * testapp search ...
0
votes
1answer
54 views

Command “>” failing in Embedded Linux only

I'm developing an app in Qt for Embedded Linux where I want to see how much (%) of the given partition is occupied. I found on the web that a way to do this would be by calling the df command passing ...
1
vote
3answers
160 views

The equivalent of cmd “for” in bash?

I'm a Linux newbie, and I only know little about bash (or any Linux shell - but I just use bash). I'm used to using for %c in (*.*) do {something} in cmd in Windows, and I really feel inconvenient ...
0
votes
2answers
47 views

How to use variables properly in this little script?

Here is a little script to retarget old-wrong symlinks that I want to make interactive. #!/bin/bash # retarget (broken) symbolink links interactively echo -n "Enter the source directory where ...
0
votes
2answers
44 views

How to add a column if line contains string?

If I have a tab-delimited file containing the following lines: Sample1-Baboon 1 2 3 4 Sample2-Human 1 2 3 4 Sample3-Human 1 2 3 4 Sample4-Baboon 1 2 3 4 How can I add a new column ...
2
votes
1answer
49 views

Equivalent of “which” in sh [duplicate]

I found out today while developing a shell script that which is not a builtin for sh. What is a good equivalent?
1
vote
1answer
48 views

Display result of a command right aligned in terminal

I have a script that goes through many different checks and I use the success, failure functions defined in /etc/init.d/functions to clearly show the action result on the terminal. That works great, ...
1
vote
0answers
35 views

Autocomplete issue in bash with equal sign (=)

I am trying to make autocomplete work and wroted a piece of code to demonstrate an issue I faced up: $ cat completion.sh function _completion_command() { compopt +o bashdefault +o default +o ...
52
votes
4answers
3k views

Why is `[` a shell builtin and `[[` a shell keyword?

As far as I know, [[ is an enhanced version of [, but I am confused when I see [[ as a keyword and [ being shown as a builtin. [root@server ~]# type [ [ is a shell builtin [root@server ~]# type [[ [[ ...
1
vote
4answers
62 views

Dynamically reference a file's name

In a single directory, I'd like to replace the first line of each file with the file's name. Each file has as the first line "TestRelation." I'd like to replace it with the file's name. I know I can ...
1
vote
3answers
118 views

How to pass an array to a function as an actual parameter rather than a global variable

Is there a way to pass an array to a function as one of its parameters? Currently I have #!/bin/bash highest_3 () { number_under_test=(${array[@]}) max_of_3=0 for ((i = 0; ...
1
vote
1answer
31 views

Can .bash_profile be auto sourced after change?

I'm always wondering if there's a way to do this. I don't want to type source after changing my .bash_profile all the time.