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
5answers
139 views

Read File word by word

My problem is to read a text file word by word and recovers every word in a variable. I tried to do: while read ligne; do { for ( i=1; i<= length ($ligne); i++); do { var=$(awk '{print $i}' ...
0
votes
2answers
29 views

VNC/SSH: How to execute a command after logging in?

I'm looking for a way to create a VNC console user that executes the command screen or bash immediately after logging in so they get their own restricted shell for executing commands etc. Screen/bash ...
-1
votes
1answer
45 views

Replace mutiple strings with different values in a file using unix [duplicate]

I have a file in which the data is like below, 01,0000000,xxxxxxx/ 02,xxxxxxxx,yyyyyy/ 03,test1,41203016,,/ 01,0000000,xxxxxxx/ ...
1
vote
1answer
52 views

shell script for date checking between two days

There is date in my file, like 30-apr-2015. How can I compare this with the current date and get notified if they are equal?
0
votes
5answers
48 views

I want to design a scipt to send alert for Swap usage more than 85%

cat /proc/meminfo | grep Swap SwapCached: 460248 kB SwapTotal: 8388600 kB SwapFree: 1031900 kB I want to use this information to compare it with a threshold ...
2
votes
4answers
204 views

How to 'drop' characters from in front of a string?

I have a string that I would like to manipulate. The string is H08W2345678 how would I be able to manipulate it so the output is just W2345678? Similarly if the I wanted to drop the last 4 ...
0
votes
1answer
40 views

What is the email matching regex in basic regex for grep?

I created a text file and put some email addresses in it. Then I used grep to find them. Indeed it worked: # pattern="^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-z]{2,}" # grep -E $pattern regexfile but only as ...
3
votes
2answers
131 views

Why can't I load modules while executing my bash script, but only when sourcing it?

I am using modules to control the packages on my system and I have python/2.7.2 installed as a module. I have simple python executable python_exe.py which I am going to call from a simple 'driving' ...
0
votes
1answer
81 views

grep: Syntax error near unexpected token `('

I have this problem: I'm looking for a string inside file . Syntax is: grep -E ‘( ^ | [[:space:]] )[A-Z]{2}[[:digit:]]{2}((- | [[:space:]] )[[:alnum:]]{4}) {3} ’ (filename) When I run this ...
1
vote
2answers
98 views

Finding files that contain multiple strings

I am trying to find scripts that contain common malicious code, I need to match multiple strings within each file. What I am using is working but am not sure why I get the following in the output: # ...
1
vote
1answer
46 views

Rsync Excludes Folders

I am running a rsync script and I want to exclude certain folders. I know with rsync you have to create a .txt file and add all the excludes in there but I am wondering is it possible to just have a ...
0
votes
0answers
56 views

How to implement command history in Linux terminal?

I am using Putty as Terminal to connect a Linux server running Oracle Linux. To use a command multiple times, I have to type that command each time. There is no function of Up and Down button unlike ...
2
votes
1answer
96 views

About executing shell script

Suppose I have a shell script file foo.sh. I can do chmod + x foo.sh and change it into an executable file. In Kernighan-Pike: Unix Programming Environment (UP) they show that after this typing ...
1
vote
1answer
68 views

Output different lines when comparing two files

I have two text files with the same number of newline terminated strings. The lines in the two files correspond to each other. The lines in each file individually might be repeated. I would like to ...
0
votes
2answers
50 views

Run script on non-full bash-login invoked as “sh”

Good day I'm currently trying to modify my terminal to have the prompt displayed in a different colour than the whole rest of the shell, and I would like to make it white for normal users and red for ...
0
votes
1answer
38 views

shell sleep until next full minute

To execute a script on the next full minute I want to tell the sleep command to sleep until the next full minute. How can I do this?
0
votes
0answers
24 views

Moving Informatica data(directories) from one unix server to another unix server

Can we migrate directories from one unix server to another unix server, without the need of installation of Informatica softwares on the new unix server? If yes, then will there be any change in the ...
0
votes
4answers
67 views

How to remove line based on Delimeter in perl / Shell?

Can anyone help to remove the line in file based on delimeter(Comma), Incase if line contain less number of columns or Bad records , Need to delete those. Input File: a,b,c,d a,b,d,f c,d a,v,b,h ...
-1
votes
1answer
59 views

Some commands not working in bash script

I'm using Ubuntu 14.04.02 32bit. On doing some shell programming, I found out that running the script through the sh command sometimes cause errors. Is it because the sh command is invoking the ...
-3
votes
2answers
68 views

echo $HOSTNAME result become key to a variable

Property server1=abc,def,ghc server2=xyz,tes,iuy #!/bin/sh echo $server1 abc,def,ghc echo $HOSTNAME server1 with those info above, I want to output the output "abc,def,ghc" in a test variable. ...
1
vote
1answer
49 views

Relation between system calls and shell commands/utilities

In POSIX, Does a system call function often but not always have a command or utility in shell? Is there some rule of thumb about what kinds of system calls have corresponding commands or utilities ...
0
votes
2answers
87 views

Recursively remove files with idx > 10,000

The problem In the current working directory I have several (very many) folders and some of them have lots (like 100,000+) of files inside. My goal is getting just the folder with 10,000+ files and ...
4
votes
1answer
76 views

Source Bash automatically in terminal

How can I automatically source a particular bash script when I open a terminal window by right clicking somewhere and choosing "open in terminal"? For example, every time I open a terminal I need to ...
2
votes
4answers
145 views

How can I find the program I'm hiding in bash

Say I have PATH="home/bob/bin:/usr/bin". I am writing a bash script /home/bob/bin/foo that will do some munging and then call /usr/bin/foo. Of course I want to be able to use this script on ...
4
votes
1answer
57 views

How to make sure the $var variable in expanded in “$varsomething”?

I'm trying to run something like this for n in 1 2 3 4 5 6 7 do run_this_command whatever.$nx$n.in done The files are named as whatever.1x1.in, whatever.2x2.in, ...
2
votes
1answer
39 views

passing tmux variable into shell-command in tmux.conf

I'm trying to edit my bottom left status section of tmux. I would like it to show Session: #{session_name} The current maximum length for this string is set at 20 using this setting ...
1
vote
1answer
82 views

Why is this simple bash script throwing an error on if/then/else? [closed]

If I try to run this script: clear echo -n "please enter a value" read num if [ "$num" -eq 8 ] then echo "you entered 8" else echo "the number you entered was not 8" I get the ...
5
votes
7answers
466 views

Turn list into single line with delimiter

I have to take a list (loads) of IP addresses in this format: 134.27.128.0 111.245.48.0 109.21.244.0 and turn them into this format with a pipe in-between (IPs made up) 134.27.128.0 | ...
11
votes
2answers
826 views

What is DISPLAY=:0?

What is DISPLAY=:0 and what does it mean? It isn't a command, is it? (gnome-panel is a command.) DISPLAY=:0 gnome-panel
4
votes
2answers
389 views

while: command not found

I'm trying to do this as an April Fool's prank: make a linux machine display a message in the shell every few seconds. My thought is to achieve this by starting an infinite loop that runs as a ...
1
vote
3answers
145 views

Shell expansion for arguments?

For example: mkdir ~/{1,2,3} Creates directories ~/1, ~/2, and ~/3. It equates to: mkdir ~/1 mkdir ~/2 mrdir ~/3 But, using the same syntax in the case of CMD < argument > : brew {install, ...
-2
votes
1answer
28 views

extracting non hidden files in shell scripting [closed]

In shell scripting while listing a directory need to extract non hidden files need to remove upload, archive and download example : upload archive download simple data final .bash_logout ...
0
votes
2answers
28 views

Dividing up columns and submitting the value as stdin into a seperate program within a script [closed]

I currently have two programs written in C named "remove" and "calculate". When I call ./remove it removes some data from stdin. When I call ./calculate which takes in an argument and also data from ...
1
vote
1answer
51 views

Is it possible to establish a Socket session (between Server and Client) using shell commands ?

From what I read (only the very outline, i do not know C Language) a Socket session is established between a server and a client by calling functions for both of them in a certain order. It starts ...
2
votes
0answers
52 views

List all btrfs filesystems and subvolumes in shell

Is there a convenient way to get information on all btrfs filesystems subvolumes without resorting to C, i.e. in POSIX shell ? /sys/fs/btrfs contains info only on filesystems, nothing on subvolumes, ...
5
votes
5answers
564 views

Getting the pid's of a program line by line

I can find the pid's of my program instances by issuing command like this: pidof avconv Which is giving me results 16616 16283 16279 16198 16175 16035 15073 14049 4922 But how can I output the ...
1
vote
4answers
109 views

find: missing argument to `-exec'

when I'm trying to use this command var1=`sudo -u psoadmin -H -s ssh daill_scp@files.dc1.responsys.net find . -maxdepth 1 -type f -mtime +14 -exec ls -lh \{} \; | awk '{print $5, $9}'|egrep -v ...
3
votes
2answers
57 views

GNU Parallel: Event not found (!~)

About my code: get all .txt files for each file, execute the awk command. All files are processed in parallel if colum 3 does NOT contain "needle", write line to file Result: -bash: !~: event ...
16
votes
4answers
600 views

How can I implement a circular flow of data among interconnected commands?

I know of two types how commands can be connected with each other: by using a Pipe (putting std-output into std-input of the next command). by using a Tee (splice the output into many ...
0
votes
1answer
27 views

Aliasing a command with parameter supplied to another command

Namely: I want to alias tail -f to less +F but let tail with any other parameter supplied work the same way as before.
0
votes
0answers
62 views

echo `“hello terminal” > /dev/terminal` - works for /dev/tty[2-5] but not for /dev/pts/n

I'm trying to get to know the input output systems of unix/linux systems better. Since terminals and devices are implemented to interface as ordinary files, I assumed I could on any desired terminal ...
12
votes
9answers
3k views

Is using “while true” to keep a script alive a good idea?

I'm just jumping into unix from a different world, and wanted to know if while true do /someperlscript.pl done The perl script itself internally has a folder/file watcher that executes when ...
1
vote
1answer
72 views

How to know which platform I am using in lubuntu, ubuntu or kubuntu

I need switch script in between lubuntu, ubuntu, and kubuntu. How can I know which platform the script is running in? Because uname/lsb_release never show different in those 3 releases Lubuntu$ ...
2
votes
1answer
30 views

How do I run two processes and find out when one ends in bash

I was thinking to do something like this: command1 & command2 wait Will this work? I want to proceed when command2 finishes, but command1 can still be running.
0
votes
0answers
84 views

Backup And Restore Shell Script

I have been trying to create a script that backups up a certain directory and then restores the directory. The backup works as it should but when I try run the restore function I get the following ...
1
vote
1answer
41 views

How to interactively remove all directories matching given criteria?

My script below has two problems: The script stops after first matched directory rm -i is not quite interactive What are my incorrect assumptions that make it fail? How can I fix it? ls -1A | ...
2
votes
3answers
190 views

Double square brackets for FreeBSD

I have this code: [[ "$1" =~ [/\\]$ ]] On linux it works just fine, but when I tested it on FreeBSD an error occured : ./projekt2.sh: [[: not found and it .. I there any alternative which would ...
1
vote
2answers
54 views

pipe in shell with redirection

My understanding is that a pipe in shell like a | b redirects b's stdin to a's stdout. However, I tried ls | less < somefile, the behavior is very strange. less shows the output of ls concatenated ...
-1
votes
2answers
28 views

Create new file with spaces from argument BASH [duplicate]

I need to create new file which contains spaces in it. And it is passed through the argument. This code below creates 2 sepate files. Can anyone help me how to create 1 file which will contains space? ...
19
votes
2answers
436 views

Where is “export var=value” not available?

I have picked up -- probably on Usenet in the mid-1990s (!) -- that the construct export var=value is a Bashism, and that the portable expression is var=value export var I have been advocating ...