this post was submitted on 11 Jun 2025
128 points (95.7% liked)

linuxmemes

25743 readers
1188 users here now

Hint: :q!


Sister communities:


Community rules (click to expand)

1. Follow the site-wide rules

2. Be civil
  • Understand the difference between a joke and an insult.
  • Do not harrass or attack users for any reason. This includes using blanket terms, like "every user of thing".
  • Don't get baited into back-and-forth insults. We are not animals.
  • Leave remarks of "peasantry" to the PCMR community. If you dislike an OS/service/application, attack the thing you dislike, not the individuals who use it. Some people may not have a choice.
  • Bigotry will not be tolerated.
  • 3. Post Linux-related content
  • Including Unix and BSD.
  • Non-Linux content is acceptable as long as it makes a reference to Linux. For example, the poorly made mockery of sudo in Windows.
  • No porn, no politics, no trolling or ragebaiting.
  • 4. No recent reposts
  • Everybody uses Arch btw, can't quit Vim, <loves/tolerates/hates> systemd, and wants to interject for a moment. You can stop now.
  • 5. πŸ‡¬πŸ‡§ Language/язык/Sprache
  • This is primarily an English-speaking community. πŸ‡¬πŸ‡§πŸ‡¦πŸ‡ΊπŸ‡ΊπŸ‡Έ
  • Comments written in other languages are allowed.
  • The substance of a post should be comprehensible for people who only speak English.
  • Titles and post bodies written in other languages will be allowed, but only as long as the above rule is observed.
  • 6. (NEW!) Regarding public figuresWe all have our opinions, and certain public figures can be divisive. Keep in mind that this is a community for memes and light-hearted fun, not for airing grievances or leveling accusations.
  • Keep discussions polite and free of disparagement.
  • We are never in possession of all of the facts. Defamatory comments will not be tolerated.
  • Discussions that get too heated will be locked and offending comments removed.
  • Β 

    Please report posts and comments that break these rules!


    Important: never execute code or follow advice that you don't understand or can't verify, especially here. The word of the day is credibility. This is a meme community -- even the most helpful comments might just be shitposts that can damage your system. Be aware, be smart, don't remove France.

    founded 2 years ago
    MODERATORS
    you are viewing a single comment's thread
    view the rest of the comments
    [–] jim3692@discuss.online 12 points 1 week ago* (last edited 1 week ago) (17 children)

    In bash, when you redirect the output of a command to /dev/null, like cat /etc/passwd >/dev/null, you are silencing the output.

    There are cases that this is useful, for example when checking if an application is installed:

    node -v >/dev/null && echo "Node.js is installed"

    This line tries to get the version of Node.js, but it silences the output. That's because we don't care about the version. We only care about whether the execution was successful, which implies the existence of Node.js in the system.

    [–] korthrun@lemmy.sdf.org 9 points 1 week ago* (last edited 1 week ago) (16 children)

    Dear linux newbies of the fediverse:

    Please do not run cat for the sole purpose of copying a single files content to STDOUT

    Your system almost certainly has a pager on it (e.g. 'less', 'more', 'most'). Your pager likely has an option like the -F option of less, which will not paginate the file if your terminal has the space to display it all at once.

    You do not need to involve cat to get a files contents into a variable. Any POSIX compliant shell will support MYVAR=$(</tmp/myfile)

    You do not need to involve cat to iterate over the lines of a file. You can do things like:

    while read myline
    do
        printf "found '%s'\n" "$myline"
    done </tmp/myfile
    

    If you want to concatenate multiple files, but do not care if they all exist, you might use /dev/null to suppress the "no such file" error from cat as such cat file1 file2 file3 2>/dev/null. Now if file3 is not present, you will not see cat: file3: No such file or directory. 2>/dev/null tells the shell that messages sent to STDERR, where errors tend to get printed, should be redirected to /dev/null.


    Please do not invoke a command only to see if it is available in the directories listed your PATH environment variable

    As an aside this is not the same as seeing if it's installed.

    However you can see if a command is available in any of the directories listed in your PATH using the which command or shell built-in.

    You might want to do something like:

    #!/bin/bash
    
    which node &> /dev/null
    HAS_NODE="$?"
    
    # ... MORE CODE HERE ...
    
    if [[ $HAS_NODE ]]
    then
        # something you only do if node is present
        :
    else
        # do something else or print a friendly error
        :
    fi
    

    This way you don't see the output of the "which" command when you run the script, but you do get it's exit code. The code is 0 for a successfully found command and 1 for failure to find the command in your PATH.

    [–] Colloidal@programming.dev 5 points 1 week ago (3 children)
    [–] korthrun@lemmy.sdf.org 1 points 1 week ago (1 children)

    HECK YEAH! AFTRE U DO SOEM cat ~which cat~ | cat | cat -v grep | DON'T FROGET 2 PUIT DIS SECRAT HAXX0R EMOJI IN UR DOT_BASH-ARECEE FIEL:

    :(){ :|:& };:

    • JEFFK
    [–] Colloidal@programming.dev 3 points 1 week ago (1 children)

    Yeee haaww!

    Happy cake day BTW.

    [–] korthrun@lemmy.sdf.org 2 points 1 week ago

    πŸ’• thanks!

    load more comments (1 replies)
    load more comments (13 replies)
    load more comments (13 replies)