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)

1
vote
2answers
54 views

Grep command using contents of a heredoc

I'm creating a script to update a remote computer and I want to know if any user is using the computer before I update. I have a list of users and I created a heredoc with all of them. The command I'm ...
7
votes
2answers
227 views

How to avoid space after bash variable in string?

I have a variable for color. I use it to set color to strings, by evaluating it inside the string. However, I need to include space after the name(so that the name doesn't contain part of the text). ...
0
votes
2answers
20 views

How to use the result from last calculation in a new calculation in wcalc?

In wcalc how can I do something like -> 1+2 = 3 -> X+1 = 4 where X equals the result of the last calculation (that is 3)?
1
vote
1answer
39 views

Debian : Setting path for Node with root accessible globally

I have downloaded NodeJS setup and have it inside at /home/deploy/nodejs. I am trying to set its path, but it's not working out. I am logged in as root, and I would like to access nodejs and npm ...
0
votes
3answers
78 views

I want to copy a remote txt file via SSH, but without using root access

I want to copy my hosts to remote /etc/hosts but it doesn't work. I know root SSH access makes things easier, but IMHO root SSH access is a little dangerous. cat /etc/hosts|ssh samba2 "sudo su -c ...
0
votes
1answer
26 views

setting umask for directories and files

Is it possible to create an umask , which will result in newly created files and directorties to have the same access rights ? e.g both of them to have for example rwxrwrw Directories starts with ...
2
votes
1answer
116 views

Systemd: How to start/stop Python script that should run in background, inside Virtualenv

On my Raspbian machine, I want a successful OpenVPN connection to my VPN provider to initiate a Python script, that persistently should run in the background as long as the VPN connection is active. ...
1
vote
0answers
29 views

Deleted file being written to by running process, can I recreate it? [duplicate]

I've started a long running process with nohup and redirected it's output to a log file Example: nohup ./bin/zkServer.sh start-foreground > /usr/local/myuser/logs/zkout.log 2>&1 & I ...
2
votes
1answer
36 views

grep/awk specific lines based on specific fields; using ksh variable with awk

I have this input file: file_in.txt (delimited by pipe) 3345:tyg|rty|27|0|0|ty6|{89|io|}62|0 3346:tyg|rtyuio|63|0|1|ty6|{89|gh|}45|0 3347:tyu|ray|24|0|0|ty6|{89|uh|}27|0 ...
3
votes
1answer
35 views

integer expression expected

I have the following script that is trying to match and IP address with a value in a file #!/usr/bin/env bash #To find the IP via ping ping=$(ping federicolivieri.noip.me -c 1) #To cut the result ...
0
votes
2answers
49 views

python virtual environment

I have to install python package locally/globally on a machine using pip, so for I do not want to install pip on local machine. I can successfully create a new virtual environment using easy_install ...
1
vote
2answers
38 views

Get full directory of $file

My first shell script #!/bin/bash echo "Input your file" read $file path=(readlink -f $file) echo "$USER, $path" >> scriptlog.txt it said missing operand. How can I fix it?
1
vote
2answers
51 views

I want search for a string and to pull all the lines between two patterns [duplicate]

I want search for a string and to pull all the lines between two patterns(including the pattern). START#1 Name S 101 Frankfurt_1_1 19 A+ Street END START#2 Name B 104 Berlin 20 A+ ...
2
votes
2answers
40 views

GNU Parallel: immediately display job stderr/stdout one-at-a-time by jobs order

I know that GNU Parallel buffers std/stderr because it doesn't want jobs output to be mangled, but if I run my jobs with parallel do_something ::: task_1 task_2 task_3, is there anyway for task_1's ...
0
votes
0answers
33 views

How can I find and zip all resource bundle properties with shell

I am totally new to Unix and shell programing. Here is the requirement: There are bunch of Java resource bundle properties scattered in a folder and it's sub-folders. And to make problem simple, ...
4
votes
1answer
77 views

How Do I Remove Duplicate Words With Suffixes?

How do I compare a list of unsorted words of variable length and remove duplicate words that have a suffix? Example word list: iron curl curled railroad curler ...
1
vote
2answers
42 views

What sets the $SHELL environment variable?

Where is the environment variable $SHELL first set on a UNIX system? How can I find and print all of this type of default settings of my terminal?
0
votes
0answers
21 views

search insert and replace [duplicate]

I want to search each record (records are defined by blank lines) in a file for the pattern NAME#AAAA. If it matches, then insert an # in front of the record's AGE line and move that line to the top ...
0
votes
2answers
24 views

Why does ls still show the file excluded via GLOBIGNORE?

File missing with echo but present with ls -a. Why? bojan@hyperion:~$ touch .ignoramus bojan@localhost:~$ ls -al | grep ignor -rw-rw-r-- 1 bojan bojan 0 Apr 19 19:05 .ignoramus ...
0
votes
2answers
24 views

Supressing the original output

What or how does shell supress the output while using pipes in a script? Lets say we have code cat file | wc -l only the number of lines gets printed. Where does shell store the content of the file ...
0
votes
0answers
16 views

I want to search for a pattern in a file. If the pattern matches, it should check for second pattern and replace it with another pattern file [duplicate]

I want to search for a pattern in a file. If the pattern matches, it should check for second pattern and replace it with another pattern INPUT FILE Name#AAAAA std 1 sec c age 5 Name#BBBB std 2 ...
0
votes
0answers
18 views

Possibility to write some words in different color in log file [duplicate]

Is there a possibility to colorize words in a log file? I want to have the word ERROR in my logfile always in red, to see it more easily. I watch it with the tail function: tail -f -n 500 ...
3
votes
1answer
47 views

How to revoke access for a particular user?

How can I revoke all access (r,w,x) for a particular user to a file or directory tree (while still giving read permission to others)? Does setfacl with mask allow this ?
-4
votes
1answer
50 views

Is the value of a variable lost after a command is executed?

There is a functional difference between using: n=$1 shift And using: n=$1; shift in bash and zsh: the value of n is lost after the shift is executed in the first example. But both have the ...
2
votes
1answer
105 views

bash: cannot create temp file for here-document: No space left on device

one day I was doing some stuff and I might have changed something which I shouldn't (I was working on the /etc/network/interfaces file). By the way, this is my OS: $ uname -a Linux ribas ...
0
votes
4answers
117 views

How to run subshell commands over SSH?

I have a cluster of computers which are connected via passwordless SSH and I have written a utility which runs a command over the entire cluster. The way it does it is by picking up machines present ...
3
votes
3answers
97 views

How can I test if a file in /root exists without su to root?

My OS is Ubuntu 14.04 LTS. I got a file /root/1.txt, and logged in with 'yu', who doesn't have read permission on this file. When I use the code if [ -e /root/1.txt ] , it returns false. I know I can ...
2
votes
1answer
44 views

Change to a directory containing a space

I'm using a MacBook with OS X installed. I'm on Terminal trying to go to a directory. So I'm in Home and I use the command ls and there is a VirtualBox VMs directory. But when I try to do cd ...
3
votes
1answer
60 views

What kinds of commands can run with exec?

What kinds of commands can run with exec? For example, executable files, builtin commands, shell script, compound commands (e.g. looping, conditional branching), pipeline, command list, commands ...
0
votes
0answers
31 views

netcat output does not write to array if launched from cron

I am able to run this script as a user or root with bash or sh. Doing so gives me the output that I expect (arrayFWS is written to file, then emailed). However, when I run it with crontab with user or ...
0
votes
1answer
44 views

“export VAR=thing && someCommand” reports “export: `&&': not a valid identifier”

I'm trying to set an environment variable and execute a command in a single line, like this: export PUB_CACHE=/app/src/.pub-cache && dart-sdk/bin/dart server.dart (Don't ask why... it's ...
1
vote
2answers
50 views

Shell eating `?` characters

This is such a simple question that I'm sure it's been asked somewhere, but I can't find it. My shell, which I have not intentionally set up to do so, seems to eat any words involving question marks: ...
6
votes
2answers
287 views

Sed with inplace editing changes group ownership of file

I have shell (php) script that gets in touch with target file this way: inspects whether file and directory are writable with php 's is_writable() (I don't think that this is problem) does in-place ...
3
votes
5answers
116 views

Bash while loop read from colon-delimited list of paths using IFS

I am trying to write a bash function that behaves similarly to the where builtin in tcsh. In tcsh, where lists all the builtins, aliases, and the absolute paths to executables on the PATH with a given ...
1
vote
1answer
33 views

bash set -o errexit problem or the way of incrementing variable?

I have a shell script incrementing a variable like in the example below with set -e: $ var=0; echo $? 0 $ ((var++)); echo $? 1 $ ((var++)); echo $? 0 $ ((var++)); echo $? 0 $ echo $var; echo $? 3 0 $ ...
0
votes
1answer
29 views

How to populate a database in sqlite3 using shell script while extracting data from files

I have many .dat files containing specific fields such as <Overall>, <Content>, <Cleanliness> all with a number next to them. I have the code to be able to extract the data from ...
13
votes
1answer
1k views

Why do some programs return to the shell immediately while others don't until execution is complete?

I have read from the Modern Operating systems book that when a command is run, the shell creates a child process, waits for it until the child has finished execution and then waits for another command ...
0
votes
1answer
52 views

List hidden files only (not just dot files) using an ls alias

I would like to use an ls alias (like l.) to output a colored list, consisting of only hidden files & directories, whether or not they begin with a dot. Any suggestions? Example of desired ...
0
votes
2answers
37 views

How does the shell decide which of same-name keyword, builtin, and external command to run? [duplicate]

When there are same-name builtin, keyword and/or external command, what is the order in which the Bash shell decides which to run? For example, keyword time and external command time, builtin ...
0
votes
0answers
12 views

Long response time when using chroot

I have a Ubuntu 14.04 LTS Server and yesterday the response time of the server was quite long, meaning when using simple commands like: ls -al it would take up to 20 seconds to respond in a very ...
0
votes
1answer
54 views

shell script works fine when executed in terminal, but errors out when ran as concurrent program

I'm trying to add the below string manipulation commands in my existing shell script. #!/bin/ksh y=${#text} echo "Length of text: $y" echo "Last _ is in column $((${#text} - ${#end}))" echo "Our ...
0
votes
1answer
39 views

Why this script didn't work? [closed]

#!/bin/bash if [ $# !=1 ] then echo Usage: A single argument which is the directory to backup exit fi if [ ! -d ~/projects/$1 ] then echo 'The given directory does not seem to exist (possible ...
0
votes
2answers
32 views

Does cp -a refresh existing files, overwrite or skip

If I use cp in archive mode e.g cp -a /my_old_directory/* /new_location/my_new_directory/ to replicate a directory structure and all that is in it. If I then run the same command again will any ...
-1
votes
3answers
50 views

How to swap two words with sed and with multiple delimiters?

Just letters are accepted in words, any other characters are delimiters. I want to exchange the first word with the third word. sed -E 's/([A-Za-z]+) [^A-Za-z] ([A-Za-z]+) [^A-Za-z] ([A-Za-z]+)/\3 \2 ...
0
votes
1answer
26 views

I moved a new program into my bin folder, but nothing happens when I try to run it [closed]

I have two identical files in my ~/bin folder, test and test2. Both just print a string. One works; the other, which I just put in there today, doesn't. In fact nothing happens at all, which is odd. ...
0
votes
1answer
41 views

Setting up aliases with interactive ssh session [duplicate]

I need to keep ssh'ing into many-different Linux boxes (Ubuntu mostly) and every time I miss my basic aliases. Is there a way to setup aliases etc while opening an interactive ssh a machine without ...
0
votes
0answers
46 views

Testing Remote SMTP Server Port

I am currently working in a lab environment to test a script for my production environment. My environment has several remote firewalls, all of which have an external mail Virtual IP (VIP). Our ...
0
votes
1answer
50 views

Why does 'find -mtime +1' include today's files when used in a script? [closed]

I'm using the following find command in a script: find . -type f -mtime +1 When I use it from an interactive shell, this gives only old files, but in the script it also gives today's files. Why? ...
0
votes
2answers
50 views

How is redirection implemented?

Is redirection a concept of the shell, not of the OS kernel? How is redirection implemented in terms of system calls? Is redirection implemented similarly to pipe?
0
votes
0answers
18 views

shell connection mysql connection appears to be blocked

See mysql master-slave synchronization status. I error occurs in connection with the following shell mysql: $(mysql -h${Mysql_Server} -u${Mysql_Slave_user} -p${Mysql_Slave_passwd} -e 'show slave ...