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
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
52 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
289 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
121 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
34 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
30 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
33 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
47 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
51 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
19 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 ...
0
votes
2answers
123 views

Unable to execute bash script inside expect script

i have a expect script like #!/usr/bin/expect ..... spawn passwd expect "password:" send "password" .... .... .... ~/test.sh Wile executing this, I'm unable to run bash script test.sh. How to ...
0
votes
0answers
17 views

useradd failing [duplicate]

Debian 8, I'm trying to allow a user to run Wireshark. user1@system:~$ sudo useradd -G wireshark user11 useradd: user 'user11' already exists However: user11@system:~$ groups user11 cdrom floppy ...
3
votes
3answers
59 views

How to make two commands consume input from stdin sequentially?

The following perl script consume-10-lines-and-exit reads ten lines from stdin and prints them. After that it exits. #!/usr/bin/env perl use strict; use warnings FATAL => 'all'; for (my $i = 0; ...
1
vote
1answer
49 views

How to organize files in Linux/Unix shell?

I would like to try to organize my documents, and I was told that I can do this using the linux/unix cygwin terminal. I searched for the command in google but all I ever did find was organizing the ...
3
votes
1answer
41 views

Combining every two column values in file

I have a file with (with only one line) with multiple columns say 4 (in this case) : A B C D And I want the output as every possible combination of column values taking 2 at a time like: AB AC AD ...
1
vote
1answer
28 views

Remove certain types of files except in a folder

I have a command in my makefile for clean: rm -rf */*.o */*.cmo */*.cmi */*.cmx */*.cma */*.cmxa */*.annot Now I would like to write a cleanpartial that removes these files except those in the ...
3
votes
2answers
81 views

execute command from find called by find

Is there a way to call find recursively? I would like to search for files matching a given pattern only in directories matching another pattern. Basically: for each (sub)directory D matching ...
1
vote
2answers
50 views

Define a variable to awk pattern matching from bash

I am trying to grab 100 lines after the text "time: X" with X in {0,40,80,...,200}. Here is what I have so far: #!/bin/bash start=1 end=5 for i in $(seq $start $end);do j=$(($i*40)) awk '/time: ...
1
vote
0answers
28 views

Passing external parameter to .exe on Windows using winexe from Linux

I am trying to execute a .exe on Windows from Linux using winexe. This exe requires an external parameter (string) to be fed alongwith. With the following command I have succeeded in initialising the ...
1
vote
1answer
35 views

code to display the text TRUE

I'm a complete newbie and I'm starting to learn the basic for shell scripts. So I apologize if this question is very simple for most users. I'm trying to display the text TRUE to the screen if a file ...
2
votes
0answers
47 views

Prevent scp and less commands reading interactive tcsh script

I'm using tsch through PuTTY, and let's start by this: please don't try to convince me to migrate to another shell...:) It's being a long time that commands like scp and less didn't work well for me. ...
0
votes
0answers
21 views

vim + tmux: some shortcuts broken?

When I am using vim inside of tmux, some of my shortcuts are broken. E.g. I have bound Ctrl + up/down and Shift + up/down in my .vimrc and when I'm running vim inside of tmux these shortcuts do not ...
3
votes
2answers
103 views

Filter files generated by `find` by parsed output of `file` command

I'm writing a quick tool to inspect the contents of a node.js node_modules folder or python virtualenv for native dependencies. As a quick first approximation to this I wrote the following command. ...
0
votes
2answers
40 views

Flow control using Unix shell

I need to do an exercise at the university, its all about reading 3 values and identify if there is any duplicated value, which value is the greatest and which one is the least, the idea is if you ...
0
votes
1answer
33 views

How to insert a string before a matched string

How can I insert a string before a matched string. Suppose I want to insert a string a before "if (PROTOCOL == "https://")" string. Please tell me how can I do this?? or How to search and replace ...
0
votes
2answers
44 views

return first instance of characters from a list

Lets say I have the output of this command saved to a file. cat /dev/urandom | tr -dc '[:graph:]' | fold -w 1000 | perl -pe 's/(.)(?=.*?\1)//g' | head -n 50 I would like to compare only the first n ...
0
votes
1answer
28 views

Please verify the result which i get using grep for korn shell

when i run the command ps -ef | grep ksh on my server i get the result as - /bin/ksh ./abc.ksh ./xyz.ksh where abc and xyz are my shell scripts. what does this symbolize ? Is one script calling ...
3
votes
3answers
54 views

All files in a directory that do not end in a specific string?

I want to find all text files in a directory that do not end with the string: hello world How can I do this?
1
vote
1answer
35 views

Creating if/than statement to move files to another location based on value of 1 column?

I have thousands of xyz (latitude,longitude,elevation) text files that I want to separate by latitude or longitude. How and what commands could I use to create an "if latitude(column1) is greater than ...
0
votes
0answers
29 views

Is there a way to get partition information of a disk with sysfs?

my first question here - so please, don't be too hard with me... As the title says: I am wondering if there is a way to get partition information of a disk with sysfs. I know about some different ...
0
votes
1answer
30 views

how to input a file as a variable in a shell script

I need to input the path of a file in shell script as a variable and use the file in the same script.Suppose the path is /home/pi/dest/file and i want to use the file as a variable.Can anyone tell me ...
0
votes
0answers
21 views

Emptying a log file getting updated with 2>&1 output redirection [duplicate]

I have a server which constantly writes outputs and errors to stdout and stderr. The command line I use for running my server is: Server options-list > log.txt 2>&1 & Now the problem ...
0
votes
1answer
30 views

Printing Space Between Strings

#!/bin/bash ARRAY="185.18.207.66 31.18.212.113" result="" for i in $ARRAY do result=$(printf '%s %s' "$result" "$i" "checked") done paste <(printf "%s\n" $result) I am trying to print ...
0
votes
1answer
33 views

Shell script getting 'permission denied' despite using umask 000 before command

I have a shell script (build.sh) that ends by attempting to copy some files into a new directory. However it says: mkdir: cannot create directory ...
1
vote
1answer
19 views

variable doesn't change after find & while [duplicate]

My code var=34 find $1 -type f | while read line; do file_status=`file "$line"` file_name=`echo $line | sed s/".*\/"//g` line_length=${#file_name} if [ $line_length ...
1
vote
2answers
90 views

Escaping in bash

Given a text message, I need to programmatically generate a bash command to open terminal emulator and show this text in it. For example, for HelloWorld input string I need to return the following ...
0
votes
0answers
26 views

How to convert the timestamp to readable date format [duplicate]

$timestamp="160402074632" Dates=$timestamp +"%Y-%M-%D" I want this to be converted to a readable date format like “Thu Dec 9 12:50:32 CET” and store it in Dates variable if i give echo $Dates , i am ...
8
votes
2answers
415 views

Wait for stdout stream to finish and then add its contents to a file

I am trying to run a command in bash where I have a command 1 which accepts a large amount content through stdin and then outputs that content to a file.txt, however, command 1 generates a stream of ...
10
votes
2answers
271 views

What are the security issues and race conditions in using `find -exec`?

From the find man page: -exec command ; There are unavoidable security problems surrounding use of the -exec action; you should use the -execdir option instead. -execdir command {} + ...
0
votes
2answers
44 views

Extracting a certain folder from a tarball - how do I tell it where to put the file once extracted?

I've looked around at multiple sources for this question and I know how to extract the file, but neither source told me how to state where to put the folder once it has been extracted. I tried this: ...