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
1answer
59 views

Got “syntax error near unexpected end of file” in bash script

I'm making an script that gives me a day like this jjj/yyyy when I give it a day like this dd/mm/yyyy and I need it to have an error when you don't write correctly but I'm starting and it's not ...
28
votes
4answers
1k views

Does /usr/sbin/nologin as a login shell serve a security purpose?

In my /etc/passwd file, I can see that the www-data user used by Apache, as well as all sorts of system users, have either /usr/sbin/nologin or /bin/false as their login shell. For example, here is a ...
8
votes
4answers
385 views

How to assign space-containing values to variables in bash using eval

I want to dynamically assign values to variables using eval. The following dummy example works: var_name="fruit" var_value="orange" eval $(echo $var_name=$var_value) echo $fruit orange However, ...
0
votes
1answer
41 views

openSuse, not running the cron job

I have created a cron job in the /etc/cron.d/dispatchingEmail_I the permissions of dispatchingEmail_I are the following: -rw-r--r-- 1 root root 84 Sep 11 19:52 dispatchingEmail_I content of ...
3
votes
1answer
329 views

while using '$?' expression in bash script

I'm writing a simple bash script #!/bin/bash ls xyzzy.345 > /dev/null 2>&1 status =' echo $?' echo "status is $status" which finds the file xyzzy.345 and logs the result to /dev/null. ...
11
votes
2answers
206 views

Why does cat x >> x loop?

The following bash commands go into an infinte loop: $ echo hi > x $ cat x >> x I can guess that cat continues to read from x after it has started writing to stdout. What is confusing, ...
1
vote
2answers
54 views

Find doesn't want to find *.sh in certain level [duplicate]

I have a problem with find. It doesn't find *.sh files if I am in certain directory level. It does, however, find *.sql files. /path$ cd do_not_upload/updates/1.1.1/ ...
4
votes
2answers
112 views

How can I force bash to deallocate a brace expanded variable without name?

For benchmarking, I ran the command: for i in {1..100000000}; do echo "$i" line >> file done Bash expanded the braces and stored the list 1 2 3 4 5 6 ... 100000000 in memory. I thought ...
1
vote
1answer
44 views

Is autocompletion for applications done by shell?

When I type evince, and then hit tab, the bash shell will list all files that can be opened by evince, which seems to be based on the ext part of the filename. Is this done by shell or the ...
2
votes
3answers
59 views

Repeat Last N commands [duplicate]

In bash, I tried writing a script to run the last N commands. For say, N=5 for i in {1...5} do !-5 done The problem is that !-5 gets replaced by the 5th-last command on my shell (say time) and ...
10
votes
6answers
956 views

What is the reverse of echo -e?

If I have a string with nonprintable characters, new lines, or tabs, is there a way I can use echo to print this string and show codes for these characters (e.g., \n for new line, \b for backspace)?
4
votes
3answers
126 views

How do I capture stdin to a variable without stripping any trailing newlines?

In a shell script... How do I capture stdin to a variable without stripping any trailing newlines? Right now I have tried: var=`cat` var=`tee` var=$(tee) In all cases $var will not have the ...
2
votes
1answer
36 views

Can you change timestamp format for history command on tcsh

When I run history command (on tcsh), it only prints the TIME portion of the timestamp and omits the date: 3 15:07 echo $PATH 4 15:07 ls -la In bash, you can use HISTTIMEFORMAT ...
2
votes
1answer
261 views

unexpected EOF while looking for matching `"' - bash script

I just wrote a bash script (im a Newbie to shell-scripting ;) ) and always getting this EOF-Error. So here is my script (only works on OS X): #!/bin/bash #DEFINITIONS BEGIN en_sq() { echo -e ...
0
votes
1answer
58 views

$PATH environment variable does not seem to be recognized

I've made a fresh install of Debian Wheezy, and installed zsh to it. Few days after, I've done a vanilla installation of TeX Live 2014, so I added the necessary binary paths to my $PATH. Now I started ...
1
vote
2answers
54 views

Run command on startup for one user

I made a new user on my server. The user is not logged into the bash shell on startup. To do this I can run /bin/bash --login and it works. Where do I place this command so that it runs ...
6
votes
2answers
183 views

echo of a string with an exclamation point

Here are what I put in bash and the results I got about 'echo': $ echo '!$' !$ $ echo "!$" echo "'!$'" '!$' I'd like to know how 'echo' deals with the second input. It seems to me that ...
0
votes
2answers
51 views

Find an archive and extract it in the directory where it is located

I want to find a tar file which is presented in any directory and un-archive it in a one line command. I am able to find it separately from home directory. but only can extract it from directory ...
1
vote
0answers
133 views

Cannot SSH after switching to Netgear router

I have Comcast Xfinity internet. When I was sent their Wifi router/Cable modem combo box, I was able to use SSH perfectly. However, since the Wifi from the box was weak, I decided to buy my own ...
5
votes
2answers
57 views

bash crashed with for loop [duplicate]

The question may be trivial but with this simple for loop for i in {1..10000000}; do echo "$i" line >> file done my shell crashed after some elaboration time (the tab in the terminal emulator ...
4
votes
1answer
82 views

How to catch a signal in command line?

I asked this question. SIGPIPE signal is generated to stop the execution of the command as told in the answer. But how do I capture this signal and gracefully terminate the command? The command exits ...
2
votes
2answers
43 views

Regarding getting Date - n days Date

Suppose I have a particular date stored in a variable (date_m) . I want ((date_m)-25) date. For eg: I have 15/09/2014 stored in my variable , then I want 21/08/2014 returned if I subtact 25 from the ...
2
votes
2answers
180 views

Test if telnet port is active within a shell script

I am trying to create a script to test whether it is possible to login via telnet. I do not want to really log in; therefore, expect is not needed. I just want to see if I am able to get a login ...
2
votes
3answers
60 views

When was the script started?

What I want is, -bash-3.2$ ps -aef | grep 29137 jeeadm 9794 1190 0 09:22 pts/2 00:00:00 grep 29137 jeeadm 29137 1 0 Sep02 ? 00:00:21 Java Second Row, Fifth Column entry, as in ...
14
votes
3answers
1k views

why 'echo --help' doesn't give me help page of echo?

I tried 'man echo' in Bash and it told me that 'echo --help' will display help then exit, and similarly, that 'echo --version' will output version and exit. But why it doesn't work ? 'echo --help' ...
1
vote
3answers
186 views

Execute a file if a command is not found

When I try to execute files in Linux, I'm always annoyed by the need to write ./executablefile instead of just executablefile. I get why it's done, so it won't have an ambigous input, one that is a ...
1
vote
2answers
47 views

Difference in output from shell script

I am running a simple shell script which has a for loop and kicks off 16 threads in the back ground and waits for each of them to finish before moving on the next commands. Here is the shell: ...
0
votes
1answer
46 views

in Shell Scirpt I want to use ::ssu <USERNAME>

I want to ssu or alternate command in shell script. However it's asking for password in middle of shell script. I don't want to do that. Any alternate command or suggestion? E.g. ssu ...
1
vote
0answers
123 views

Load a background image or set the background color if Konsole/Shell is running SSH

I want to set my laptop to load an image in the shell's background or set the background color to red if I'm connected via SSH. How can this be done? With a bash function in .bashrc? I have: Set the ...
1
vote
4answers
165 views

why do we not need export here?

$ IFS=";" $ read first second i am;a_i b c $ echo $first i am $ echo $second a_i b c $ echo $IFS Am I right that read first second is a subprocess of the current shell process? If yes, why don't ...
1
vote
1answer
41 views

Can I start a background process with a specific working directory?

Say I have this structure /masterscript /a/script1 /a/b/script2 In masterscript I spawn the other scripts as background processes: "/a/script1" & "/a/b/script2" & The problem is that ...
0
votes
1answer
66 views

Running shell script on cluster in parralel

I thought dsh(Distributed Shel) will be a good option but when i ran my shell script across my nodes, I didnt get expected output, dsh -aM -c bash /home/cloudera/bash_script.sh server2@x.x.x.110: ...
2
votes
1answer
72 views

How to sort files based on the json property value inside the file?

I've downloaded list of videos via youtube-dl and each file has corresponding .json file containing certain properties. So I would like to sort the files based on the selected json property which is ...
1
vote
0answers
65 views

How to start a process chain from the shell

Is it possible and if so how do I: Start a /bin/bash process that is not bound to a terminal from a terminal? Hence, a shell process that shows up in the process tree as init -- bash. (Shells ...
0
votes
1answer
35 views

How to automate ktutil to immediately list keytab entries?

I use MIT ktutil a lot on Linux and I am fed up using the following sequence, even if command shortcuts and file name completion are here to help: ktutil rkt my.keytab l Isn't there a way to get ...
6
votes
2answers
2k views

Why does source give an error “cannot execute binary file”

I have small file that does initialize a tmux session and then creates some windows. After some debugging and tweaking things worked fine until I renamed the text file (with the tmux commands) from ...
7
votes
2answers
379 views

Bash string concatenation used to build parameter list

Given this piece of bash: PARMS='-rvu' PARMS+=" --delete --exclude='.git'" echo $PARMS rsync ${PARMS} . ${TARGET} The echo shows the PARMS string as expected, no error is displayed, but rsync ...
1
vote
2answers
62 views

Apply given rsync exclude patterns on given directory

I have a setup where I use rsync to mirror some source directory to a (remote) destination except for some files and locations defined witch rsync exclude patterns: # Useless files - thumbs.db - *.~ ...
1
vote
2answers
176 views

I want to suppress “no access to tty” error message?

I have a bash script where I use ssh to connect to another server and run some commands there. I found some sites that the error (Warning: no access to tty (Bad file descriptor). Thus no job control ...
9
votes
1answer
253 views

How to “correctly” start an application from a shell

I find it hard to phrase the question precisely but I will give my best. I use dwm as my default window manager and dmenu as my application launcher. I hardly use GUI applications aside from my ...
2
votes
0answers
59 views

How can you get the current terminal line (the one that is still editable by the user)?

I need a way to use the current line which the users typed into as variable for a shell function. my current code, which can be called by ctrl+r zle -N search bindkey "^R" search search () { read ...
1
vote
2answers
52 views

Passing print pattern as a variable to awk

I am trying to use awk to print variables from various columns in a line delimited by , .The columns and pattern which I want to print is stored in another variable b. The pattern a and print patter ...
1
vote
1answer
128 views

Pattern replacement

Please can anyone explain to me in brief the syntax of this command. Explanation in terms of how actually this command is written significance of each and every character used. I know the output of ...
0
votes
2answers
137 views

Login by ssh , exec one command and i don't want to quit the bash

I want to change PS1 when i ssh another centos strshell = 'PS1="remote!"' os.system("ssh -i %s -l%s -p%s %s %s"%(SSH_KEY,SSH_USER,SSH_PORT,des,strshell)) ssh quit automatically. I want to ...
1
vote
2answers
62 views

Confusions mitigation while working similar environments in multiple servers

I often have to open multiple ssh sell terminals of remote servers together., eg. Dev and test. These paths and applications are exactly similar. And I am often confused if I run a particular command ...
2
votes
2answers
55 views

How do you get a count of all file extensions on a hard drive using the gnu+linux terminal?

On windows I have a program that can count all the files on a hard drive and the output shows a list of file extensions and a number (which showed how many files on the drive were for example are ...
5
votes
2answers
457 views

Is there any way to read lines from command output?

I have a pre process command to output a file ./preprocess.sh > preprocessed_file and the preprocessed_file will be used like this while read line do ./research.sh $line & done < ...
2
votes
3answers
243 views

Saving individual output lines into variables

I'm using find -mtime -2 to find files modified in the past 24 hours or less. The output looks like this. /home/user/logs/file-2014-08-22.log /home/user/logs/file-2014-08-23.log I need to save the ...
4
votes
1answer
4k views

Syntax error near unexpected token `('

When I use below code in SSH terminal for CentOS it works fine: paste <(printf "%s\n" "TOP") But if I place the same line code in a shell script (test.sh) and run shell script from terminal, it ...
2
votes
1answer
454 views

Running sh script: «Permission denied» despite the executable bit and root rights

I installed Debian in VirtualBox (for various experiments which usually broke my system) and tried to launch the VirtualBox guest addon script. I logged in as root and tried to launch autorun.sh, but ...