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
3answers
40 views

Replacing line with its line number

How can I replace the whole line with no matching pattern just with the number of the line? sed -i "${line}p c\ "$PWD" " file.txt
0
votes
2answers
42 views

how to split the string after and before the space in shell script?

I am having a variable which shows on echo like this $ echo $var 129 148 I have to take only 129 as output. How will I split 129 and 148?
0
votes
1answer
21 views

Rename and copy/move sets of similar named directories to another location

For a set of directories with similar names at different location, /foldX/dirA with sub-directories aa1 aa2 aa3 aa4 aa5 /foldZ/dirA with sub-directories aa1 aa2 aa3 /foldY/dirA with ...
-1
votes
0answers
41 views

What exactly is Ctrl + s? [duplicate]

In my terminal, if I press Ctrl+S it 'freezes' output, which can then be resumed with Ctrl+Q. What exactly happens here? What library/program supplies this functionality or at least says what ...
11
votes
2answers
3k views

How do I tell a script to wait for a process to start accepting requests on a port?

I need a command that will wait for a process to start accepting requests on a specific port. Is there something in linux that does that? while (checkAlive -host localhost -port 13000 == false) ...
5
votes
2answers
197 views

How to count duplicated last columns without removing them?

I have a file that contains 4 columns. I want to compare the last three columns and count how many times they occur without deleting any of the lines. I just want the count to be present in front of ...
1
vote
1answer
34 views

mv to file with

I ran the following mv command, apparently by mistake using backslashes by mistake instead of slashes. mv 2015-02-02_flyer_ppces.pdf ..\PPCES2015\2015-02-02_flyer_ppces.pdf The output is empty. ...
4
votes
2answers
201 views

BASH base conversion from decimal to hex

In Bash, how does one do base conversion from decimal to another base, especially hex. It seems easy to go the other way: $ echo $((16#55)) 85 With a web-search, I found a script that does the ...
19
votes
5answers
5k views

How can I create an alias for a git [action] command (which includes spaces)?

Most of my my aliases are of this form: alias p='pwd' I want to alias git commit so that it does git commit -v But trying to create an alias with a space gives an error: $ alias 'git commit'='git ...
2
votes
2answers
131 views

An error of variable type?

I've an error that I don't understand, it seems that that the problem is that my parameters into the shell are not of the same type as what they are in my SQL Database. For a better understanding: ...
8
votes
2answers
210 views

How bash treats “> >()”

While experimenting with output redirection and process substitution I stumbled upon the following command and its resulting output: me@elem:~$ echo foo > >(cat); echo bar bar me@elem:~$ ...
0
votes
3answers
126 views

How to ssh and execute a remote script within a local shell script?

I have a shell script which will kick off a series of jobs on a remote server. I can ssh into this server (but it does require a password!) and run the scripts manually, but there are certain steps ...
-2
votes
1answer
36 views

Append the content of a file to the value of a variable in ksh

Can we append the content of a file to the value of a variable in the Korn shell? How? /bin/ksh: $ B.11.31 Oct 1 2008 01:54:10 $ Version 11/16/88 blok.c $Date: 2008/08/20 12:15:51 $Revision: ...
0
votes
1answer
42 views

introduce a c script in a bash file [closed]

My problem is to recover data keyed in text file in bash. I seek the command that can perform this task and I used sed, awk and even cut but I have not succeeded. One friend of mine suggested to ...
0
votes
1answer
20 views

Why doesn't commons-daemon ./configure recognize $JAVA_HOME? [closed]

I'm trying to install a tomcat 7 server. I'm following these instructions from the tomcat 7 docs. I also set my JAVA_HOME variable in ~/bashrc as well as ~/.bash_profile and /etc/profile. I can do ...
0
votes
2answers
1k views

Why alias does not work in AIX (korn shell, .profile)?

I have these files in my home directory: drwxr-xr-x 3 meuser staff 256 Oct 12 13:11 . drwxr-xr-x 102 bin bin 4096 Sep 30 12:28 .. -rw------- 1 meuser staff ...
5
votes
3answers
199 views

Echoing stdin when running an ed(1) script

Given the following ed script, $ cat helloworld a hello world . ,n ,s,o,O,g ,n Q I would like to obtain somehow the interactive output $ ed a hello world . ,n 1 hello 2 world ,s,o,O,g ,n 1 ...
2
votes
2answers
155 views

How does one append a unix timestamp on a filename which is inside an argument?

To be more specific, I want the Unix timestamp to be appended to my file name: db:backup --database=mysql --destination=s3 --destinationPath=date+random.sql --compression=gzip However, this gives ...
4
votes
4answers
134 views

Insert new lines with missing values (NA)

I would like to insert new lines in text files if there are missing values. I have for example the following text file (A.txt), for which line 5 is missing. In addition, as the file should have 12 ...
1
vote
1answer
41 views

What is an alias really doing?

I'm looking for a way to check what an alias is really doing, without having to check the ${HOME}/.profile file, or whatever other file where you can define an alias. For example, if I run ll and I ...
2
votes
1answer
17 views

Making XMODIFIERS=@im=none emacs24 standard

I run emacs as XMODIFIERS=@im=none emacs24, otherwise some multi-keys for typing things like à won't work. How can I make this option permanent, so when I type emacs24, it runs as XMODIFIERS=@im=none ...
0
votes
2answers
51 views

Regular expression for excluding data within a certain range

I want to remove all the IP addresses which are of the format 10.20.30.* and whose last 3 digits fall in the range 0 to 200 and move all the remaining IPs to a new file. I've put the IP list to be ...
-4
votes
1answer
50 views

shell script for two numbers [closed]

Write a shell script to take two numbers from command line and show result of dividing small number with bigger number. Also note that it should not accept zero or negative number. If user enter ...
2
votes
1answer
122 views

Transform .csv into 3 columns and a row

Sample Input: id,Product1,Product2,Product3,Product4 1,0.1,0.3,0.8,0.7 2,0.6,0.7,0.5,0.9 I need output as : id,productname,product_val 1,Product1,0.1 1,Product2,0.3 1,Product3,0.8 1,Product4,0.7 ...
1
vote
0answers
46 views

How to move /usr folder and replace it with saved copy [duplicate]

If I made a backup of /usr with: # cp -r /usr /usrRESERVE1 how can i switch it back after some time: 1# mv usr usrRESERVE2 2# mv usrRESERVE1 usr second command will not work because mv is inside ...
1
vote
1answer
44 views

Ctrl+C process termination without Terminal killing

I started using Sublime Text 3 to compile my FreeFem scripts (interpretator PDEs package solver) under Ubuntu 14.04. To invoke the interpretator I customized the build system as follows "shell_cmd": ...
3
votes
2answers
69 views

save the number of files only in a specific folder

I'm using this script to save the number of files in a main folder, but it also counts the subfolders inside that main folder. nfiles=$(ls -1 /home/userA/mainfolder | wc -l) Any advice how I can ...
5
votes
4answers
8k views

What is the syntax of a complex condition in shell?

If want to express the following test in shell (sh) : if ( a == 1 && ( b == 1 || b == 2 )) { ... } So far, the best I have been able to write is this : if [[ $a -eq 1 ]]; then if [[ $b ...
3
votes
2answers
133 views

How do you stop a bash shell expansion?

I know some methods for stopping process. When I type: echo {1..999999} > filename.txt I can't stop it from running. I can stop other processes with Ctrl+C | Ctrl+D | Ctrl+\ and etc. But none ...
0
votes
0answers
26 views

Linux . Kali on android 4.2.2

hope this topic finds you well E: Unable to Locate Package thats the error that occur when i try to install any tool in kali on android I'm using Android with version 4.2.2 and kali is working well ...
5
votes
4answers
4k views

Bash, how to let some background processes run but wait for others?

I have (yet) another wait, &, && control flow question.. Say I have a script something like this where I want to do as much work at the same time as possible: # may take some hours ...
1
vote
2answers
34 views

Need special validation for shell script

I want to create a bash script which will have lot of options while executing. # script.sh --dry-run --user <parameter1> --pass <parameter2> I heard about getopt option but looks like ...
-1
votes
2answers
56 views

Difference between 'echo' and 'echo -e' [closed]

What is the difference between echo and echo -e? Which quotes should be used to execute a command after echo ie: echo "..." or echo '...'? Also what functions are available for the command echo?
0
votes
2answers
27 views

Why is wget still failing even after enclosing the URL with double quotes?

I enclose URLs I want to wget with "" since most of them have spaces, braces, etc. It usually works fine, but I can't get this URL to work: wget "http://xxxx/Sankarea - 6 - It`s Because I... Ran ...
1
vote
2answers
49 views

sh -c: Unterminated quoted string error [duplicate]

I've spent hours trying to understand the following error. My Script CMD="sh -c 'echo \"a\"'" $CMD Error: "a"': 1: "a"': Syntax error: Unterminated quoted string of course when I do echo $CMD ...
1
vote
2answers
275 views

How to put $@ in quotes?

My bash script looks like this: #!/bin/bash grep -r --color=always $@ . | nolong The file is saved in /usr/bin/findstr Everything's ok when I run this: findstr hello But when I run this: ...
1
vote
1answer
35 views

Saving colored output regardless of the source

How can I save colored output to a file regardless of the source when the sources turn coloring off if they detect their stdout isn't a terminal?
1
vote
1answer
21 views

zwrite handling of “@” symbol

I've been using zwrite to create simple message popups in AIX, and it handles @ symbols weirdly, even when they're strong quoted. I'm running these commands in ksh. As an example, echo '1 @ 2 @@ 3 ...
5
votes
4answers
376 views

list graphical processes from terminal

Do no confuse the question here with how to list processes graphically, that is not what I am asking. In the Terminal, how can i see which processes have a GUI? as in things like firefox, vlc, ...
11
votes
2answers
3k views

What is the difference between “du -sh *” and “du -sh ./*”?

The title says it all. What's the difference between those 2 commands? NOTE: I'm more interested in the * and ./* part.
-1
votes
1answer
23 views

Remove line breaks in a FASTA file

I have a fasta file where the sequences are broken up with newlines. I'd like to remove the newlines. Here's an example of my file: >accession1 ATGGCCCATG GGATCCTAGC >accession2 GATATCCATG ...
3
votes
3answers
119 views

Understanding Bash's Command Substitution

I am trying to understand how exactly Bash treats the following line: $(< $FILE) According to the Bash man page, this is equivalent to: $(cat $FILE) and I can follow the line of reasoning for ...
29
votes
3answers
7k views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
44
votes
1answer
1k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
9
votes
1answer
2k views

Are dash, ash and sh script 100% compatible?

I wanted to know whether scripts written for dash, ash, and sh are 100% compatible? Are there any added features to dash or ash, or syntax change? From what I heard, ash is a direct descendant of ...
-2
votes
1answer
47 views

How to parse json output through shell / Python [closed]

I am running a curl command which gives me json response. Now I want to parse the response output to get the keys and corresponding values from the output or getting value for a particular key. I ...
24
votes
3answers
18k views

How to remove a single line from history?

I'm working in Mac OSX, so I guess I'm using bash...? Sometimes I enter something that I don't want to be remembered in the history. How do I remove it?
0
votes
0answers
33 views

How can I disable FTP access/login for users

I want to temporarily disable the FTP Access of the FTP users I have tried following commands for user "aadmi" but still able to login sudo passwd -l aadmi which said Locking password for user ...
1
vote
1answer
35 views

Not getting the desired output for echo command [duplicate]

Below is my script. #!/bin/bash SERVERS="sl20rht00-t" #SERVERS="shcbrht01-t" USR="adm-dt-c" for host in $SERVERS do ssh -tt $USR@$host 'sudo cp /etc/sudoers /Backups/sudoers_11thmarch2015; sudo cp ...
0
votes
2answers
61 views

ssh inside a script with 'command' instead of “command”

I am trying to run commands on various nodes of our cluster automatically via a simples script. I have seen that I can run: #!/bin/bash echo "Machine: "$HOSTNAME; ssh machine2 'echo Machine: ...