Questions tagged [shell]

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, …). For shell scripts with errors, please check them in http://shellcheck.net before posting here.

Filter by
Sorted by
Tagged with
0
votes
0answers
37 views

How do system administrator's create unique 15 character passwords (2 special, 2 alpha, 2 numeric, 2 uppercase, 2 lowercase), for their own accounts? [closed]

I am asking about the UNIX system administrator's personal UNIX account (a standard unix user account) which can be used to "su" or "sudo" into a root account. This has to be ...
5
votes
3answers
100 views

Adding a column with random values to end of CSV

I have a CSV with a list of users, and would like to add a column with a one-time-use randomly generated password, unique to each user. My script works... but then it just keeps going indefinitely ...
1
vote
1answer
44 views

In Bash, how can I compute and capture the result from an intermediate node in a pipeline?

In Bash, how can I compute and capture the result from an intermediate node in a pipeline? For example, given a list of integers and a command or function maximum, using a single Bash pipeline, how ...
3
votes
2answers
53 views

Reading empty string from CSV file in BASH

I'm using the following gawk script to read values from the first column of the csv file file.csv. I use gawk since I don't want any embedded commas to be ignored. col=`gawk ' BEGIN { FPAT="([^,]...
0
votes
1answer
13 views

How to gzip all .BRIK in all Sub-Directories

I have a lot of files with .BRIK extension that take up a lot of space and need to be gzip. However, the files are scattered in multiple folders and few-level deep. I cannot find an answer to gzip *...
0
votes
1answer
29 views

Match multiple words to replace a pattern

I have a file that has data something like .spec.nodes.brokers.runtime.properties.broker.http.numConnections=15 .spec.nodes.clients.runtime.properties.broker.http.numConnections=17 .spec.nodes.servers....
1
vote
1answer
21 views

fish - Run multiple abbreviations with another abbreviation

I have a few abbreviations that I want to run on one command. Let's say given this config: abbr command1 "echo 1" abbr command2 "echo 2" abbr command3 "echo 3" I want ...
0
votes
0answers
21 views

Auto run script manjaro linux

I am using Manjoro Gnome . I am running a shell script when my system boot up using systemd and it works perfectly fine . The problem is when my system go to sleep or get lock automatically after ...
1
vote
1answer
18 views

How to run remote server shell script with environment parameters on Jenkins pipeline

I am attempting to run a shell script on a remote server in jenkins scripted pipeline using the sshScript remote: remote, script: command. This line of code currently looks like this: sshScript remote:...
0
votes
1answer
32 views

How to print command output on same line, to overwrite previous one? [duplicate]

I'm trying to execute a shell script that checking device status, by keep executing certain commands in a while loop until the output is changed to certain one, I was wondering if there is a way to ...
1
vote
0answers
27 views

Bash read csv file using awk and save output in array

I have an excel file and column 10 has multiple values like below, Designation Header ----------------- Student Teacher Teacher Organization Director Organization Director Organization Head Student ...
1
vote
3answers
53 views

Performing CSV Split effectively keeping limit into consideration

I have to split a large CSV file into multiple small files with a limit of 1000 records in each small file. However, I don't know beforehand how many records will be there in that large CSV file. I ...
2
votes
0answers
48 views

How to loop through the for loop and calculate the results of for loop?

I am trying the below script in which I am expecting to receive two files in the filesdir folder on date1. If the date is 1 then it should check if two files are received or not, so thats why I m ...
1
vote
1answer
23 views

Why I am getting error in the else part of my shell script? [duplicate]

I am trying the below script in which I am expecting to receive two files in the filesdir folder on date1. If the date is 1 then it should check if two files are received or not, so thats why I m ...
2
votes
1answer
21 views

SFTP connection issue after 10 seconds

I'm trying to send files through SFTP by using the below script but after 10 seconds the SFTP connection closed and some files did not send without getting any errors. Script: #!/bin/sh HOST=xxx.xxx....
0
votes
2answers
138 views

syntax error near else in shell script

I am trying the below code. In that I am trying to check I get two files in the mentioned directory below, then I want to get completely out of the while loop! But if I have not received the files ...
-2
votes
0answers
34 views

Quickly check if file is a text (non-binary) file

I have a list of files where I want to filter out all non-text (binary) files. I know that I can use file to check the filetype, but this is abysmally slow for huge numbers of files (I have omitted ...
0
votes
2answers
42 views

After ssh to remote hosts, grep used inside EOF gives output “No such file or directory”

Scenario: I have a script to connect to remote hosts and grep specific keyword from a log file. Without using EOF the ssh was getting freezed but when used heredoc (EOF) that issue was gone. All my ...
1
vote
1answer
52 views

Get the unresolved pwd of a shell from another process

I'm hitting an issue where I need to get the unresolved symlink of a shell process. For example given a symlink ~/link -> ~/actual, if bash is launched with a $PWD of ~/link, I need to fetch that ...
-3
votes
3answers
36 views

How to get the sum of the digits after the last period (.) in the given strings in unix?

The strings are from a 3 columned file (Serial Number, Company, Country) - Entity.csv 8ABNML.006543.FG.988, ABC Pvt Ltd, Japan 9KILPS.006324.FG.455, Roger Exports, Korea 3GHJIL.223451.FG.6778, ...
1
vote
0answers
48 views

combining the two awk file

I am trying to detact the selfish node based on the ncr and energy equation.. I have already detacted the selfish node, but based on ncr and energy separately.. and I had a problem combining the two ...
2
votes
3answers
194 views

How can I configure RANDOM for getting the same 32 bit range of random numbers, like by using SRANDOM?

Environment: Debian Bash What is known: RANDOM gives a random number in a range of 15 bits by the following: echo $RANDOM SRANDOM gives a random number in a range of 32 bits by the following: echo $...
1
vote
2answers
34 views

Best way to pad stdin to desired length with NULL

I have the following requirement. I have an input stream that I need to truncate to a certain fixed length of bytes. I do not know the length of the input stream beforehand. If the stream is less in ...
4
votes
1answer
130 views

why is “read” through each line of a file much faster than “xargs”

I have a large input file which contains 30M lines, new lines in \r\n. I decided to do something silly and compare the speed of counting all lines via read -r compared to xargs (stripping the \r first,...
-1
votes
1answer
50 views

./shell.sh: line 6: [: =~: binary operator expected

I'm trying to execute the following shell script, where I'm trying to keep executing a command in an infinite loop and until the output is not equal to a certain substring checkDeviceStatus=$(adb ...
7
votes
4answers
648 views

How to pipe filenames with spaces from a list file into “grep”?

First, I think the fact that I'm using cygwin is highly relevant here. In theory, I already know how to do this: cat file | xargs grep pattern The problem is, some of the file paths in file have ...
0
votes
0answers
35 views

mutt fails to run (to send mails to gmail adress exactly)

here is my local .muttrc (without names/passwords as XXXX...) set ssl_starttls=no set ssl_force_tls=no set imap_user=XXXXXXX@gmail.com set imap_pass=XXXXXXXXX set from=XXXXXXX@gmail.com set realname=...
0
votes
1answer
104 views

How to replace `\t` with a TAB character in a string, in a way that is independent of the shell? [duplicate]

I have a script that is going to be executed by sh and bash on Debian Linux. When it is called by sh, the following echo command works perfectly, and replaces \t with 3 spaces. However, it fails when ...
0
votes
2answers
71 views

How to install glib 1.2 on new system?

I try to install glib 1.2 on Ubiuntu 21.04 to run old c program After succesfull ./configure --build=i386-linux-gnu --host=i386-linux-gnu I try make with error : make check Making check in . make[1]...
13
votes
1answer
925 views

What does !cp:$ do?

I saw this command in the documentation of one of the programs in my work: cp company-sso /usr/local/bin/company-sso ; sudo chmod +x !cp:$ I'm aware that : will stop the next command from being ...
0
votes
2answers
49 views

Execute an shell script with php in a safe way

I'm working on a technically breakthrough for a web interface (php) to process audio files with a separation module (spleeter https://github.com/deezer/spleeter). My demo app didn't work. See below. ...
1
vote
1answer
47 views

lsof command not found during shell script execution in Jenkins pipeline

I'm trying to get process id which is running against specific port hence manually following command successfully executed - lsof -i :9090 -t But if I run same code on same machine through shell ...
0
votes
2answers
40 views

Check for line in text bash

This is a really stupid question but I can't find an answer anywhere. So I have a command that prints out lines of text like this: htop kvantum alacritty And I need to check for a line, not a ...
2
votes
1answer
23 views

searching for a string in multiple servers out put in file

Hi folks I am trying to do a search multiple servers (for now 3 but it may go up). the output the result in the file along with the server i found the string. I am doing this: for host in $(cat ...
0
votes
1answer
48 views

AWK subtract 3rd with 1st line, 6th with 4th etc recursively, and then average out

I have a file with a list of numbers, like this 4.90889 4.92681 4.99236 5.29358 5.3115 5.37706 5.9354 5.95332 6.01888 I need to subtract the third number with the first, then procede with the next 3 ...
0
votes
0answers
18 views

remotely querying a DB file and then setting the answer as a env variable to be used [duplicate]

I am writing a script and I am trying to query a WebLogic JDBC file. Then do a search for other servers that have this variable in their assetmanagement-xa-ds-jdbc.xml it works when I execute it: ssh ...
0
votes
2answers
38 views

How to use while IFS=, to read a field from the file and then subsequently replace this field as well

while IFS=, read -r Q1 Q2 Q3 Q4; do #Reading from a CSV file Replace Q2 with the string "Nan" #Replace the second comma separated value with a string I am looking for how to do this ...
3
votes
1answer
30 views

dash and local keyword not resetting shell

dash shell (unlike bash and busybox ash implementation where both examples print foo: '') takes value of previously defined variable, i.e. guarding with local does not work: $ foo=ee; bar() { local ...
0
votes
0answers
20 views

C-shell prompt color

I wan to change the color of my csh shell. I've edited my .cshrc file, following the instruction I've found here, and included this in it: set yellow="%{\033[1;33m%}" set end="%{\...
5
votes
2answers
926 views

Can it possibly work if I assign two shells to SHELL in cron?

Recently I started the process of gradual switching my shell to nu and because of it I thought about assigning its path to SHELL in cron. Having read a good part of the manual at man 5 crontab, I took ...
2
votes
1answer
323 views

How to redirect the output of a pipe to >/dev/null

I would like to redirect the STDOUT and STDERR of the whole pipe to /dev/null. Considering this is my command: sudo lsof -i:22000 -t | xargs kill -9 I know this is the wrong way of doing it: sudo ...
1
vote
1answer
27 views

if statement with dynamic variable names

I created dynamic variables. for (( c=1; c<=2; c++ )) do eval "prev$c=$number"; done prev1, prev2 for (( c=1; c<=2; c++ )) do eval "current$c=$number"; done ...
0
votes
1answer
18 views

Writing data to binary file after reading the data from binary file in shell script?

Can anyone let me know how to read a binary file for some data and write that data to the new binary file in shell script and so on? I am using Linux. Note: cat file1 > file2 : not required as this ...
0
votes
0answers
15 views

lubuntu autostart wont work 20.04

i have one .desktop file in autostart folder which contains exec to sh script [Desktop Entry] Type=Application Exec=/home/user/script.sh Hidden=false X-MATE-Autostart-enabled=true Name[en_US]=TEST ...
1
vote
1answer
31 views

How to empty a file with terminal?

All my sites include a script that saves in a file all the fake google IPs that are not in google IP range. Then with a script once a day I add all the IPs to the firewall. while read line; do sudo ...
0
votes
1answer
24 views

Customize zsh prompt to start at a specified directory and show all subdirectories

My current prompt looks like: luke@Lukes-MacBook-Pro ~/Documents/abc % which uses PROMPT='%n@%m %~ %# ' in my .zshrc file. My .zshrc also contains cd abc since this is where I would like to start all ...
0
votes
1answer
71 views

Using command substitution in sed

I have a markdown file that consists of many different headings, I am writing a CI script that modifies one of the section with every push to the repo. My README.md is as follows, README.md # Title ......
0
votes
1answer
33 views

Awareness of text under prompt?

Continue of this question: here In 2nd my_processes function: my_processes() ( for c in sc rc ed cnorm civis; do eval "$c=\$(tput $c)"; done trap 'printf %s "$rc$ed$cnorm"; ...
0
votes
0answers
24 views

install-prereqs-ubuntu.sh: 43: install-prereqs-ubuntu.sh: Syntax error: “(” unexpected

Code : https://github.com/ArduPilot/ardupilot/blob/master/Tools/environment_install/install-prereqs-ubuntu.sh root@LAPTOP-DGMQV86H:~/Github/ardupilot/Tools/environment_install# chmod +x install-...
-2
votes
0answers
25 views

Envirment variables are not loaded in shell script. Is this the expected behavior?

Run from powershell echo $env:path you get C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\...

1
2 3 4 5
216