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
93 views

Can a command be executed without a shell?

I am developing a binary executable program command to execute programs and return the output into a text field. The parameters to the command involve the command itself as it would be typed on the ...
18
votes
5answers
531 views

Find files that a user can write, efficiently with minimal process creation

I am root. I would like to know whether a non-root user has write access to some files - thousands of them. How to do it efficiently while avoiding process creation?
0
votes
2answers
53 views

Can not execute command with root in a remote Linux host

I try to migrate shell code to Python fabric code. The issue I meets is that Python can not execute command with root in a remote Linux host. Could anyone meet this issue and figure it out? I am very ...
1
vote
1answer
35 views

Shell read script for sftp

I have this working: % cat read.sh !/bin/sh file=list.txt while read line do echo "$line" cut -d' ' -f27 | sed -n '$p' > file2 done < "$file" % cat list.txt sftp> #!/bin/sh sftp> ...
4
votes
5answers
88 views

command which works like ~ (tilde) symbol to represent some directory

cd ~/scripts. This will go into scripts directory in my home. Similar to this, I want some "alias" kind of setting, which will allow me to enter some other directory so that, cd xxx/mywork -> will ...
0
votes
1answer
33 views

Take output field data string into variable

I want to grep for some specific lines from a log file, and then capture a specific part of that output in a variable and use it in other commands. The grep command I have is the following, where $1 ...
2
votes
1answer
38 views

xargs not prompting after each line

I want to know the size of all the data files in my directory. I tried using the following command. The file names all start with data_. find . -name 'data_*' -type f | xargs ls -sh -n1 -p I do ...
3
votes
3answers
43 views

How can I list every port serving a web page

I have a number of servers, all with various HTTP(S) services accessible on a variety of ports. It's incredibly difficult to keep track of which service is available under which host and what port. ...
1
vote
4answers
215 views

Wildcards for filepaths aren't working in grep [duplicate]

I need to grep words like these: ABC-DEF AB2-DEF AB3-DEF AB-DEF So I was trying: grep AB*-DEF grep -w -AB*-DEF grep -w AB*DEF But neither of them are working. Please help.
1
vote
1answer
28 views

Restrict ssh access per user based on conditions

Is there a way to restrict a user to only use ssh to connect via SFTP, but disallow that same user to login to a secure shell terminal? I only want the user to have the ability to connect by an SFTP ...
1
vote
2answers
27 views

Separate bashrc file for ssh sessions to avoid Unison Errors

Recently my Unison started throwing up some strange error whenever I tried to sync between my laptop and my PC. I realized that I had added a line in bashrc that would print my pending tasks whenever ...
1
vote
2answers
44 views

Aliasing using for or while loop in .bashrc

Can I use a for or while loop when I have similar pattern in the aliases that I put in my .bashrc file? For example, I have: alias c0='ssh computer-1-0' alias c1='ssh computer-1-1' alias c2='ssh ...
0
votes
3answers
110 views

How to loop through lines in a file which contains * in each line

I have a file that contains about 800 lines. All the lines contains 1 * character in it. I need to loop through the lines in the file so I used the following simple for loop for i in $(cat ...
-1
votes
1answer
23 views

How can I execute and export in a single shellscript

I have two shell scripts. $ cat java_alternative_7 #!/bin/sh sudo update-java-alternatives -s java-7-oracle $ cat java_home_7 #!/bin/sh export JAVA_HOME=/usr/lib/jvm/java-7-oracle It's simple that ...
2
votes
1answer
29 views

Can not access my external hard drive.

I am fairly new to Linux and have been trying to move some files around with terminal on my external hard drive but I can't seem to get it to work. I am using a generic external hard drive with a ext4 ...
4
votes
3answers
47 views

Why can't I open a shell from a pipelined process?

I've condensed my problem into the following code: #include <stdio.h> int main(){ char buffer[256]; printf("Enter input: "); scanf("%s", buffer); system("/bin/sh"); ...
3
votes
1answer
77 views

difference between /bin/bash and “.”

Env: Ubuntu 14.04 I have a file called bc on my home folder. The whole content of the file is func() { local a b=() echo $0 } func Note there's no #!/bin/bash at the beginning. Then, if I ...
2
votes
2answers
58 views

Reliably identifying the path to the directory containing the running script

There are plenty of answers in SO to address this question: Can a Bash script tell what directory it's stored in? Unix shell script to find out which directory the script resides? And there are a ...
10
votes
1answer
147 views

Track certain parameters on some command

Let's say that I have a command git branch (always with a couple of words) for example. What I want is to keep track of when this command is executed with arguments. For example, if I execute the ...
0
votes
1answer
20 views

A generic cron wrapper that records all output

I am hoping to write a cron wrapper that records all output in a folder $CRON_LOG_DIR. It would be used as, e.g., follows: * * * * * $CRON_WRAPPER "<job name>" "command" which would record ...
1
vote
1answer
62 views

Using MPI with a .sh script?

I am a beginner with Unix and MPI. I have a runPR.sh script as below DIR=/directory/buildagain/bin/Project FILELIST=$1 while read FILE do echo "Processing ${FILE}..." ./makeInp.sh ...
2
votes
2answers
41 views

Replace between patterns that start and end in different lines

I have a file with the following format: Whatever1 Whatever2 Whatever3 binaries=( text1 bin2 ohhh3 ) Whatever4 Whatever5 Whatever6 I need to replace whatever inside lines binaries=( and ) with a ...
0
votes
1answer
77 views

Ubuntu changing shell on me

This Ubuntu machine is showing errors when I start a new terminal. The problem is this: When bash completion is sourced (. /usr/share/bash-completion/bash_completion) the shell taking place is not ...
5
votes
2answers
130 views

scp command behaves differently when used with expect utility

expect -c 'spawn scp -C -o CompressionLevel=9 ~/partFiles/* abc@10.200.4.15:/export/home/abc/; sleep 10; expect password; send "secretPassword\n";interact' throws - ~/partFiles/*: No such file or ...
2
votes
1answer
61 views

How to replace “&” with “&amp;” except when already part of an XML entity?

I have a file (xml) with many &amp;/&lt;/&gt;/etc, but sometimes also some & characters by themselves. I want to change this symbol to &amp; without replacing the others. cat ...
1
vote
1answer
49 views

Pattern matching inside awk

I intend to modify the output of ls -la to display the output of file command. The below command works well for the purpose find /opt -type f | xargs ls -let | awk 'BEGIN { OFS="\t" } { sprintf("file ...
1
vote
2answers
74 views

bash - Why does type -a execute “$(printf 'a')” and is it possible to get back the original alias? [duplicate]

After i ask this question 2 days ago, i decided to make this alias in my ~/.bashrc: alias catvu="LC_ALL=C sed \"$(printf 's/[^\t -\176\200-\377]/^&/g')\"|LC_ALL=C tr '\0-\10\13-\37\177' ...
1
vote
1answer
24 views

.bash_logout or .zlogout isn't parsed when autostarting xserver directly after login on console

I made a line: [[ -z $DISPLAY && $XDG_VTNR -le 4 ]] && exec startx (right out of the Arch Wiki) at the end of .xinitrc to start the Xserver right after login on console. Whenever ...
1
vote
1answer
17 views

When not started from a terminal, Emacs does NOT pick up the SSH_AUTH_SOCK environment variable

When I don't start it from a terminal, Emacs 24.5.1 (compiled from source) doesn't pick up my environment variables. In particular, to "import" the environment variables from shell, I have in my ...
1
vote
1answer
45 views

Automate input to the shell of a program

These days many programs like mongodb, docker etc, have there own shell i.e., if you type docker -i it opens an interactive shell (similarly with mongo and other programs). Is there a way to automate ...
1
vote
1answer
32 views

Writing a tab completion script for bash

I made a shell script that reads input from user and kills a process. But in bash if the user presses Tab key then bash suggests some keyword or file names. My script however doesn't suggest anything. ...
2
votes
3answers
225 views

“ sudo: source: command not found”

$ source /etc/environment $ sudo source /etc/environment [sudo] password for t: sudo: source: command not found It seems that a different shell than bash is run to execute source ...
0
votes
1answer
31 views

csh: Terminal inherits environment variables from an unknown location

I'm on a shared machine running CentOS 5.10 that I log onto using VNC from Windows 7. Our default and official shell is csh. Every time I open a new terminal, I have three particular environment ...
1
vote
2answers
41 views

Show output of a command run inside screen if it exits with errors

I am using the screen command for starting server running in foreground. But in case there is an error when starting server I am not able to see the output of command. I have to run it again without ...
1
vote
2answers
38 views

Copy line in file if we know the pattern [closed]

We have a file which has 10 lines, and I know that some line has text QWERTY. How can I manipulate the file so that it copies that line and paste it. The output is similar to that yy and p command ...
2
votes
2answers
60 views

Weird behaviour when setting environment variables with .bash_profile: only last export works properly

I am trying to export some environment variables in Unix using the .bash_profile It reads now like this: export PATH=${PATH}:/usr/local/cuda-6.0/bin/ export ...
0
votes
1answer
24 views

zsh alias with linefeeds, commas and quotes

In my zshrc I have an alias like this: alias sl='screen -list' It fits my need (seeing what screens I have running), but the output is rather ugly: [pts/7]~% sl There are screens on: ...
11
votes
4answers
452 views

Why isn't apt-cache policy output piped?

Cannot get why $ apt-cache policy foo N: Unable to locate package foo but $ apt-cache policy foo 2>&1 | grep . is empty. Where in the latter call am I doing the wrong assumption? The ...
7
votes
5answers
447 views

Storing shell scripts [duplicate]

What is the good common practice to store shell scripts? (bash, sh, ...) For now, I have a few bash and sh scripts in my $HOME directory and I invoke them with $ bash $HOME/script1.bash arg1, arg2, ...
2
votes
2answers
31 views

Replace screen process from within screen

I have configured my shell to exec screen when it starts, unless it's already running within a screen session. So in a TTY, the process tree will look like something like this: ...
0
votes
1answer
26 views

Syntax Error while running command from another hosts [duplicate]

I run a command to fetch server uptime as below [root@localhosts ~]# printf "`uname -n` `uptime| awk -F " " {'print $3,$4'}`\n" localhosts 75 days, Now when I run same command from another ...
1
vote
1answer
26 views

How does this text reformatting happen with ack?

If I do a plain ack for a string, I get a line with the filename, and then the line numbers and the matching lines, like so: $> ack function mymodule.file 8: function myfunction1() { 16: public ...
0
votes
1answer
71 views

Shell Script Help - Automatically assign users to group

Recently, I have just started to learn linux and I am currently trying to make a shell script that can automate the task of creating user accounts, assigning them passwords and then assigning them to ...
0
votes
1answer
56 views

Strange output when echoing variable from a different user

$ sudo su - user1 -c 'echo $DOMAIN_HOME' /app/user1/DOMAINHOME This looks fine, right? However, let's dig a little deeper: $ sudo su - user1 -c 'echo $DOMAIN_HOME' | tee test.out $less test.out ...
1
vote
2answers
92 views

how to run script with a clean login shell

I am connected to remote machine Linux RH6 directly via ssh (key imported on server), when I execute a shell script with arguments for restarting the java service, I have a strange issue with ulimit: ...
3
votes
4answers
138 views

How to maintain a specific number of processes running?

I'm trying to write a shell script for converting a lot of .wav files to .mp3. I use the "find" command to find them, then the "lame" command to convert. I can use a simple for loop for this but I ...
0
votes
3answers
72 views

Remove lines in a shell script

I have this file: # more file.txt 2c2 lns-ld-wall-01-t2 old:261,260 4c4 Prive_ORANGE old:258,259 I need to remove all lines like this one 2c2 and this one 4c4. How can I do in a shell script?
0
votes
1answer
26 views

Run Application without Holding up terminal [duplicate]

If i wanted to run an application from the terminal (linux, ubuntu), how do I do so so that the terminal is still usable or that so if I close the terminal, the application still runs.
0
votes
1answer
56 views

How do I center-align a column in UNIX?

I’m trying to center-align a column using the command column. The output should look like this: temperatures 50 12 89 63 How can I do this?
3
votes
5answers
75 views

`xargs` with spaces in filenames

I'm trying to list only non-image files, searching only in the most recent 500 files. So I run ls -t | head -500 | file | grep -v 'image' which isn't right: it displays a help message. Changing it ...