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
0answers
7 views

Create variables and assign values via loop (bash)

Is there a way to create bash variables and assign them values via a loop? Something along the lines of: #!/bin/bash c=0 for file in $( ls ); do var"$c"="$file"; let c=$c+1; done
0
votes
0answers
21 views

Show last x lines of a screen session?

/etc/init.d/mc {..} status) if screen -ls | grep -q "mc"; then echo -e "[\033[32mMC\033[0m] Online" {.. needed code ..} else echo -e ...
1
vote
1answer
62 views

Bash script won't work on current directory

I'm using Kali linux which is based on Debian and wrote an script to copy some files from where the script is based to a specified directory. But when I execute my script (called CopyFiles.sh), cp ...
0
votes
0answers
13 views

Create user, directory, vhost, and mysql user faster? [on hold]

I host a lot of my client websites on my dedicated Ubuntu Server (14.12). I really need a faster way to create a directory for a new client then manually creating the user, the mysql user, assign the ...
1
vote
1answer
37 views

Can't use find -print in AWK

I'm trying to put together a command to find SUID System Executables, which are not the default ones in RHEL. To do this, I'm pulling a list of the local File System (df --local -P), piping it over ...
3
votes
1answer
29 views

How to inspect the raw contents of a partition?

I'm trying to see the contents in raw bytes of a dummy partition /dev/sda3, which I've made to be 100MiB through gparted. I want to test writing and reading on that partition. Is there a tool that ...
0
votes
2answers
29 views

Change only the year on the output of the “date”-command

date for example displays Fri Apr 17 20:16:01 IST 2015 Now I want to change only the year so date should display Fri Apr 17 20:16:01 IST 2016 in this example. How to add 1 year to the output of date ...
2
votes
2answers
37 views

Local variable as a part of global one

I have a question about something similar to this question, but I need to call global variable depending on local one. Say I want to pass either test, staging, or production as a variable to a ...
3
votes
1answer
30 views

Shell glob - substitute file path arg with file's contents

In curl command, there is --data option, which substitutes the file contents when the option value is prefixed by @ symbol like, curl -X POST --data @abc.json hostaddr.com abc.json file contents ...
13
votes
3answers
455 views

When I cd through a symlink, why does pwd show the symlink instead of the real path?

I created a soft link (ln -s 1 2) to a directory which is inside the test directory and opened the soft link (cd 2) and displayed the current path using pwd. The displayed path was ~/test/2 and not ...
2
votes
1answer
19 views

Quoting: loop over ssh-accounts, call psql on remote server

This works in the human brain, but the shell misses quoting: for h in a b; do ssh $h psql -tAc "select * from mytab where mycol='x'"; done How to quote this one liner without loosing readability?
0
votes
1answer
46 views

How can I get a shell script to change directory for me? [duplicate]

here is a small test I ran, to try and move me back to root: #!/bin/bash pwd cd / pwd It returns the current working directory, and then the correct new one, but when the script finished executing, ...
2
votes
2answers
173 views

The «sh» being launched with execl() becomes a zombie

I am spent whole half a day, but still couldn't figure, why is the dash being launched with execl call just becomes a zombie. Below is a minimal test case — I'm just fork a child, make a duplicate of ...
1
vote
1answer
41 views

using `for file in` to select multiple extension names then get the basename of “file” then concatenate an extension name

I am trying to practice my unix skills, I just learned how to use for file in *.jpg; what it does is select all files with .jpg in the working directory, but I do not want to stop there and I do not ...
0
votes
1answer
34 views

how to write a shell script to run multiple programs

I want to run two programs ssh -f mike@c15-0330-02 'cd /home && nohup Rscript L_1.R> L_1_sh.txt ' AND ssh -f mike@c15-0330-03 'cd /home && nohup Rscript L_2.R> L_2_sh.txt ' I ...
0
votes
0answers
42 views

Need to have password coded in script [duplicate]

I have to login many Servers day in day out by supplying passwords manually. Now I want to know or have a script where from I can login to any server without password (I mean to say if the ...
0
votes
1answer
38 views

shell script unable to set environment variable with the grepped value

In the shell script, I want to grep a value from the log file and set as the value of one environment. In the log file, there is one line like this: SOME_PATH=/some/specific/path In my shell ...
1
vote
1answer
34 views

Cut some fields from a text file to another

I have the following command: grep -owf champs.txt t.txt and I want to cut the result of this command from the file t.txt to another file. I know that it can be achieved by a nested command but I ...
1
vote
2answers
57 views

How are long command lines ( > $COLUMNS ) automatically wrapped to a new line?

There are several points where I/O is passed through, some of which (to my knowledge) are the shell, pty, tty, termios, terminal emulator application. In most terminal emulators, long command lines ...
1
vote
2answers
78 views

check if a variable is in list

to check if a word is in a list of words or no I wrote this script: tr -s '[[:blank:]]' '\n' < t.txt | while IFS= read -r word; do if [[ "$word" =~ $(echo ^\($(paste -sd'|' ./champs.txt)\)$) ...
1
vote
1answer
43 views

Given a *nix command, how do I find where the executable is? [duplicate]

There is a command written in bash I found from documentation from people who previously worked in this project. Now I need to locate the command's source and modify it. I tried which my_command ...
0
votes
2answers
45 views

How to search recursively in a directory for different files?

I have a x.tar file in directory /a. After untaring x.tar I got the following result: cust/ cust/01/ cust/01/INFENG/ cust/01/INFENG/scr/ cust/01/INFENG/scr/test.scr cust/01/INFENG/SQL/ ...
5
votes
2answers
449 views

How can I make xargs play nice with stdin?

$ seq 1 3 1 2 3 $ seq 1 3 | xargs echo 1 2 3 $ Mentally replace seq 1 3 with any command that lists entries one-per-line on standard out. How can I get more-or-less what you'd expect, i.e. the ...
5
votes
4answers
230 views

Change the time zone of a cronjob

I have a cronjob which is executes every day at 9:00 AM of UTC-Time. I'm in GMT+1 so it executes at 10:00 AM local time. When there is the timezone change (to daylight saving time, DST), the cronjob ...
1
vote
3answers
90 views

Bash long string, no word splitting?

I want to tidy up some script with long commands, so that for example: { somecheck || somecomand "reallyreallyreallyreallyreallyreallylongstring" } &> /dev/null & becomes something like: ...
1
vote
0answers
23 views

What Does the Output of “--help” Mean? [duplicate]

When using the --help option of a terminal program, a lot of output is produced. It usually starts with Usage: and then a bunch of things and brackets and parentheses. My question is, what doe the ...
0
votes
0answers
33 views

chrome os: crosh tab completion

Tab-completion doesn't seem to work in crosh, or even in other Chrome OS apps - it kind of does what's expected, in that it tabs to the address bar, but unfortunately that's not what I want. I could ...
2
votes
3answers
70 views

bash: error handling on find -exec

I was using this little script to find malformed images: find -name '*.jpg' -exec identify -format "%f\n" {} \; 2>errors.txt It worked well enough, but now I need to modify it slightly. Instead ...
0
votes
0answers
41 views

Counting program fails in arithmetic test

having a little trouble with this rather basic script. This script works on Bash in my macbook pro, but not on my Linux Mint desktop, which also uses bash. I can't figure out what's wrong with it, ...
2
votes
1answer
45 views

Bash - Command substitution adds single quotes

I have a problem with bash behavior while evaluating grave accents. I want to run find with optional -name: find -name "*.log" works fine, but when i want to get the -name part from nested script ...
0
votes
1answer
45 views

Print file name,Modified Date and Size with Header

How do I print file size, file name and modified date with header.Till now I have come up with: find . -regex '.*\.csv' -execdir stat --printf '%n,%y,%s' {} \; How to add header and do not print ...
1
vote
1answer
54 views

Running some parts of a script as an unprivileged user with shell environment

I am creating an instance configuration script that sets up a machine. I am running the script via sudo i.e. sudo run.sh. Most of the steps require root access but some of the script's steps do no ...
1
vote
4answers
52 views

Sed substitution grouping is appending in OSX rather than the expected sub in Linux

I've got three comma separated columns. Last name, First name, social. I'm trying to capitalize all characters in the last name column using sed 's/\([^,]*\)/\U\1/' foo.file In osx this command ...
2
votes
1answer
33 views

Syntax When Combining dd and pv

I am a linux newbie; so, sorry if this is obvious to you... sudo dd if=/dev/sda bs=64k | pv --size 1.5t | dd of=/dev/sdb Does the block size for dd go on the left side of this after the input as ...
-2
votes
1answer
88 views

Sqlplus: Command not found

I have two virtual machines ubuntu, one is a server when I installed oracle 11g express, and the other is a simple client. My goal is to run an sql query remotely from the client machine. So I ...
1
vote
1answer
40 views

How to recover a shell script I deleted from a specific folder in Debian 7?

So in a merry mood last night, I deleted an important shell script from my system. I mistook it for something else and figured it wasn't needed. I am trying to recover it. I have tried 'scalpel' and ...
0
votes
0answers
11 views

What shell extension recommends packages if command is not found and how to update it? [duplicate]

I know this question might sound a little strange but i really don't know how to describe it better. On my Debian system I have a shell extension for bash that, whenever I enter an unknown command, ...
1
vote
2answers
30 views

Problem with using expr

I've got two strings str1="( 1 + 2 + 3 + 4 + 5 ) / 3 + 5" and str2="( 1 + 2 + 3 + 4 + 5 ) / 3 + 5 * 2" The command result=` expr $str1` returns a correct value, while result=` expr $str2` ...
1
vote
2answers
29 views

Background processes mix up order of shell script execution

Can someone explain me why the script echo one && echo two & echo three && echo four gives me [1] 3692 three four one two [1]+ Done echo one && ...
4
votes
2answers
107 views

My /var/log/ is mysteriously filling up GBs in minutes! Any cure before I re-install Debian 7?

Good morning, fellow *nix enthusiasts! I have been using Debian 7 for a while now and after a recent upgrade I noticed I constantly kept running out space on my root partition. I mean to the point ...
27
votes
2answers
706 views

find(1): how is the star wildcard implemented for it to fail on some filenames?

In a file system where filenames are in UTF-8, I have a file with a faulty name; it is displayed as: D�sinstaller, actual name according to zsh: D$'\351'sinstaller, Latin1 for Désinstaller, itself a ...
0
votes
0answers
22 views

Is there a way to add a timestamp to the logs for qsub job?

I'm submitting jobs on a cluster via qsub but the error/output logs don't have a timestamp, making debugging more difficult. Is there a way to add timestamps to the logs in the bash script? Appreciate ...
1
vote
1answer
65 views

Running every command through another

I'm setting up a system in which any external command that does something with real effect must be crypthographically signed before before the system will execute them. The restrictions are in place ...
0
votes
3answers
45 views

copy the contents of a variable in a text file

I know this is a stupid question but I want to know how I can put the contents of a variable in a text file. This variable is a string that I want the code with the base64 command.But this command ...
0
votes
5answers
113 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
0answers
28 views

Cannot use --cut-dirs nor -np in wget [closed]

I'm a Unix beginner and I tried to download sra files over ftp using these commands: wget -r -nH –-cut-dirs=8 ftp://ftp-trace.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByStudy/sra/ERP/ERP007/ERP007205/ ...
0
votes
2answers
8 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
41 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
41 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
41 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 ...